Skip to content

Commit 76a7d3d

Browse files
committed
feat: add dynamic list page size options and update default page size handling
1 parent 707947c commit 76a7d3d

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

adminforth/modules/restApi.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,9 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
12031203
),
12041204
options: {
12051205
...resource.options,
1206+
listPageSizeOptions: typeof resource.options.listPageSizeOptions === 'function'
1207+
? await resource.options.listPageSizeOptions({ adminUser, adminforth: this.adminforth })
1208+
: resource.options.listPageSizeOptions,
12061209
fieldGroups: resource.options.fieldGroups?.map((group, i) => ({
12071210
...group,
12081211
noTitle: group.noTitle ?? false,

adminforth/spa/src/views/ListView.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ const customActionLoadingStates = ref<{[key: string]: boolean}>({});
262262
263263
const DEFAULT_PAGE_SIZE = 10;
264264
265+
watch(() => coreStore.resource?.resourceId, () => {
266+
if (coreStore.resource?.options?.listPageSize) {
267+
pageSize.value = coreStore.resource.options.listPageSize;
268+
} else {
269+
pageSize.value = DEFAULT_PAGE_SIZE;
270+
}
271+
});
265272
266273
const PAGE_SIZE_OPTIONS = computed(() => {
267274
const array = coreStore.resource?.options?.listPageSizeOptions;

adminforth/types/Common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ export interface AdminForthResourceInputCommon {
472472
* Page size for list view
473473
*/
474474
listPageSize?: number,
475-
listPageSizeOptions?: number[],
475+
listPageSizeOptions?: number[] | ((args: { adminUser: any, adminforth: any }) => number[] | Promise<number[]>);
476476

477477
/**
478478
* Whether to use virtual scroll in list view.

0 commit comments

Comments
 (0)