Skip to content

Commit e446c5c

Browse files
committed
fix: update data handling in afcl table for the backend pagination
1 parent 3edc8d2 commit e446c5c

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

adminforth/documentation/docs/tutorial/03-Customization/15-afcl.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,14 @@ To load pages dynamically, simply pass async callback to data:
836836
```ts
837837
async function loadPageData(offset, limit) {
838838
// in real app do await callAdminForthApi or await fetch to get date, use offset and limit value to slice data
839-
return [
839+
return {
840+
data: [
840841
{ name: 'John', age: offset, country: 'US' },
841842
{ name: 'Rick', age: offset+1, country: 'CA' },
842843
{ name: 'Alice', age: offset+2, country: 'BR' },
843-
]
844+
],
845+
total: 3 // should return total amount of records in database
846+
}
844847
}
845848

846849
<Table

adminforth/spa/src/afcl/Table.vue

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,6 @@
6666
</li>
6767
</ul>
6868
</nav>
69-
<nav v-if="typeof(props.data)==='function'" class="afcl-table-pagination-container bg-lightTableBackground dark:bg-darkTableBackground flex items-center flex-column flex-wrap md:flex-row justify-between p-4"
70-
:aria-label="$t('Table navigation')">
71-
<i18n-t
72-
keypath="Showing page {from}" 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"
73-
>
74-
<template #from><span class="font-semibold text-lightTablePaginationNumeration dark:text-darkTablePaginationNumeration">{{currentPage}}</span></template>
75-
</i18n-t>
76-
<div>
77-
<button
78-
@click="switchPage(Math.max(1, currentPage - 1))"
79-
class="afcl-table-pagination-button rounded-s-lg p-2 ms-0 text-blue-600 bg-lightActivePaginationButtonBackground border border-lightActivePaginationButtonBackground text-lightActivePaginationButtonText dark:bg-darkActivePaginationButtonBackground dark:border-darkActivePaginationButtonBackground dark:text-darkActivePaginationButtonText hover:opacity-90"
80-
> <IconArrowLeftOutline /> </button>
81-
<button
82-
@click="switchPage(currentPage + 1)"
83-
class="afcl-table-pagination-button rounded-e-lg p-2 text-lightUnactivePaginationButtonText border bg-lightUnactivePaginationButtonBackground border-lightUnactivePaginationButtonBorder hover:bg-lightUnactivePaginationButtonHoverBackground hover:text-lightUnactivePaginationButtonHoverText dark:bg-darkUnactivePaginationButtonBackground dark:border-darkUnactivePaginationButtonBorder dark:text-darkUnactivePaginationButtonText dark:hover:bg-darkUnactivePaginationButtonHoverBackground dark:hover:text-darkUnactivePaginationButtonHoverText"
84-
> <IconArrowRightOutline /> </button>
85-
</div>
86-
</nav>
8769
</div>
8870

8971

@@ -103,7 +85,7 @@
10385
}[],
10486
data: {
10587
[key: string]: any,
106-
}[] | ((offset: number, limit: number) => Promise<{ [key: string]: any }[]>),
88+
}[] | ((offset: number, limit: number) => Promise<{data: {[key: string]: any}[], total: number}>),
10789
evenHighlights?: boolean,
10890
pageSize?: number,
10991
}>(), {
@@ -113,9 +95,12 @@
11395
);
11496
11597
const currentPage = ref(1);
98+
const recievedTotalPages = ref(1);
11699
117100
const totalPages = computed(() => {
118-
if (typeof props.data === 'function') {};
101+
if (typeof props.data === 'function') {
102+
return recievedTotalPages.value;
103+
};
119104
return Math.ceil(props.data.length / props.pageSize);
120105
});
121106
@@ -124,7 +109,8 @@
124109
const end = start + props.pageSize;
125110
if (typeof props.data === 'function') {
126111
const res = await props.data(currentPage.value, props.pageSize);
127-
return res;
112+
recievedTotalPages.value = res.total;
113+
return res.data;
128114
}
129115
return props.data.slice(start, end);
130116
});

0 commit comments

Comments
 (0)