fix query builder requests pagination & pagination loading

This commit is contained in:
Julian Krauser 2024-12-31 14:52:17 +01:00
parent 79a4594878
commit 6154518cbd
2 changed files with 11 additions and 4 deletions

View file

@ -96,6 +96,10 @@ watch(searchString, async () => {
}, 600); }, 600);
}); });
watch(() => props.totalCount, async () => {
currentPage.value = 0;
});
const emit = defineEmits({ const emit = defineEmits({
submit(id: number) { submit(id: number) {
return typeof id == "number"; return typeof id == "number";
@ -151,7 +155,8 @@ const loadPage = (newPage: number | ".") => {
if (pageEnd > entryCount.value) pageEnd = entryCount.value; if (pageEnd > entryCount.value) pageEnd = entryCount.value;
let loadedElementCount = filterData(props.items, searchString.value, pageStart, pageEnd).length; let loadedElementCount = filterData(props.items, searchString.value, pageStart, pageEnd).length;
if (loadedElementCount < props.maxEntriesPerPage) console.log(loadedElementCount, props.maxEntriesPerPage, pageStart, pageEnd)
if (loadedElementCount < props.maxEntriesPerPage && (pageEnd != props.totalCount || loadedElementCount == 0))
emit("loadData", pageStart, props.maxEntriesPerPage, searchString.value); emit("loadData", pageStart, props.maxEntriesPerPage, searchString.value);
currentPage.value = newPage; currentPage.value = newPage;

View file

@ -32,8 +32,10 @@ export const useQueryBuilderStore = defineStore("queryBuilder", {
}, },
sendQuery(offset = 0, count = 25, query?: DynamicQueryStructure | string) { sendQuery(offset = 0, count = 25, query?: DynamicQueryStructure | string) {
this.queryError = ""; this.queryError = "";
if (offset == 0) {
this.data = []; this.data = [];
this.totalLength = 0; this.totalLength = 0;
}
let queryToSend = query ?? this.query; let queryToSend = query ?? this.query;
if (queryToSend == undefined || queryToSend == "" || (typeof queryToSend != "string" && queryToSend.table == "")) if (queryToSend == undefined || queryToSend == "" || (typeof queryToSend != "string" && queryToSend.table == ""))
return; return;
@ -44,7 +46,7 @@ export const useQueryBuilderStore = defineStore("queryBuilder", {
}) })
.then((result) => { .then((result) => {
if (result.data.stats == "success") { if (result.data.stats == "success") {
this.data = result.data.rows; this.data = [...this.data, ...result.data.rows];
this.totalLength = result.data.total; this.totalLength = result.data.total;
this.loadingData = "fetched"; this.loadingData = "fetched";
} else { } else {