Skip to content

Commit 486b372

Browse files
committed
fix: page numeration and improve stability in afcl table with back-end pagination
1 parent 8f634df commit 486b372

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

adminforth/spa/src/afcl/Table.vue

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
<i18n-t
4545
keypath="Showing {from} to {to} of {total}" tag="span" class="afcl-table-pagination-text text-sm font-normal text-lightTablePaginationText dark:text-darkTablePaginationText mb-4 md:mb-0 block w-full md:inline md:w-auto"
4646
>
47-
<template #from><span class="font-semibold text-lightTablePaginationNumeration dark:text-darkTablePaginationNumeration">{{ Math.min((currentPage - 1) * props.pageSize + 1, props.data.length) }}</span></template>
48-
<template #to><span class="font-semibold text-lightTablePaginationNumeration dark:text-darkTablePaginationNumeration">{{ Math.min(currentPage * props.pageSize, props.data.length) }}</span></template>
49-
<template #total><span class="font-semibold text-lightTablePaginationNumeration dark:text-darkTablePaginationNumeration">{{ props.data.length }}</span></template>
47+
<template #from><span class="font-semibold text-lightTablePaginationNumeration dark:text-darkTablePaginationNumeration">{{ Math.min((currentPage - 1) * props.pageSize + 1, dataResult.total) }}</span></template>
48+
<template #to><span class="font-semibold text-lightTablePaginationNumeration dark:text-darkTablePaginationNumeration">{{ Math.min(currentPage * props.pageSize, dataResult.total) }}</span></template>
49+
<template #total><span class="font-semibold text-lightTablePaginationNumeration dark:text-darkTablePaginationNumeration">{{ dataResult.total }}</span></template>
5050
</i18n-t>
5151

5252
<ul class="afcl-table-pagination-list inline-flex -space-x-px rtl:space-x-reverse text-sm h-8">
@@ -95,24 +95,22 @@
9595
);
9696
9797
const currentPage = ref(1);
98-
const recievedTotalPages = ref(1);
9998
100-
const totalPages = computed(() => {
99+
const dataResult = asyncComputed( async() => {
101100
if (typeof props.data === 'function') {
102-
return Math.ceil(recievedTotalPages.value / props.pageSize);
103-
};
104-
return Math.ceil(props.data.length / props.pageSize);
101+
return await props.data(currentPage.value, props.pageSize);
102+
}
103+
const start = (currentPage.value - 1) * props.pageSize;
104+
const end = start + props.pageSize;
105+
return { data: props.data.slice(start, end), total: props.data.length };
106+
});
107+
108+
const totalPages = computed(() => {
109+
return dataResult.value?.total ? Math.ceil(dataResult.value.total / props.pageSize) : 1;
105110
});
106111
107112
const dataPage = asyncComputed( async() => {
108-
const start = (currentPage.value - 1) * props.pageSize;
109-
const end = start + props.pageSize;
110-
if (typeof props.data === 'function') {
111-
const res = await props.data(currentPage.value, props.pageSize);
112-
recievedTotalPages.value = res.total;
113-
return res.data;
114-
}
115-
return props.data.slice(start, end);
113+
return dataResult.value.data;
116114
});
117115
118116
function switchPage(p: number) {

0 commit comments

Comments
 (0)