|
44 | 44 | <i18n-t
|
45 | 45 | 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"
|
46 | 46 | >
|
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> |
50 | 50 | </i18n-t>
|
51 | 51 |
|
52 | 52 | <ul class="afcl-table-pagination-list inline-flex -space-x-px rtl:space-x-reverse text-sm h-8">
|
|
95 | 95 | );
|
96 | 96 |
|
97 | 97 | const currentPage = ref(1);
|
98 |
| - const recievedTotalPages = ref(1); |
99 | 98 |
|
100 |
| - const totalPages = computed(() => { |
| 99 | + const dataResult = asyncComputed( async() => { |
101 | 100 | 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; |
105 | 110 | });
|
106 | 111 |
|
107 | 112 | 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; |
116 | 114 | });
|
117 | 115 |
|
118 | 116 | function switchPage(p: number) {
|
|
0 commit comments