|
66 | 66 | </li> |
67 | 67 | </ul> |
68 | 68 | </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> |
69 | 87 | </div> |
70 | 88 |
|
71 | 89 |
|
|
74 | 92 |
|
75 | 93 | <script setup lang="ts"> |
76 | 94 | import { ref, type Ref, computed } from 'vue'; |
| 95 | + import { asyncComputed } from '@vueuse/core'; |
| 96 | + import { IconArrowRightOutline, IconArrowLeftOutline } from '@iconify-prerendered/vue-flowbite'; |
77 | 97 |
|
78 | 98 | const props = withDefaults( |
79 | 99 | defineProps<{ |
|
83 | 103 | }[], |
84 | 104 | data: { |
85 | 105 | [key: string]: any, |
86 | | - }[], |
| 106 | + }[] | ((offset: number, limit: number) => Promise<{ [key: string]: any }[]>), |
87 | 107 | evenHighlights?: boolean, |
88 | 108 | pageSize?: number, |
89 | 109 | }>(), { |
|
95 | 115 | const currentPage = ref(1); |
96 | 116 |
|
97 | 117 | const totalPages = computed(() => { |
| 118 | + if (typeof props.data === 'function') {}; |
98 | 119 | return Math.ceil(props.data.length / props.pageSize); |
99 | 120 | }); |
100 | 121 |
|
101 | | - const dataPage = computed(() => { |
| 122 | + const dataPage = asyncComputed( async() => { |
102 | 123 | const start = (currentPage.value - 1) * props.pageSize; |
103 | 124 | const end = start + props.pageSize; |
| 125 | + if (typeof props.data === 'function') { |
| 126 | + const res = await props.data(currentPage.value, props.pageSize); |
| 127 | + return res; |
| 128 | + } |
104 | 129 | return props.data.slice(start, end); |
105 | 130 | }); |
106 | 131 |
|
|
0 commit comments