File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff line change @@ -395,6 +395,7 @@ const props = withDefaults(defineProps<{
395395 rows: any [] | null ,
396396 totalRows: number ,
397397 pageSize: number ,
398+ pageSizeOptions: number [],
398399 checkboxes: any [],
399400 sort: any [],
400401 noRoundings? : boolean ,
@@ -430,7 +431,7 @@ const emits = defineEmits([
430431]);
431432
432433const pageSizeOptionsComputed = computed (() => {
433- let options = props .resource ?. options ?. listPageSizeOptions ;
434+ let options = props .pageSizeOptions ;
434435
435436 if (! options || options .length === 0 ) {
436437 return [];
@@ -468,16 +469,6 @@ watch(() => pageSizeInternal.value, (newSize) => {
468469 }
469470});
470471
471- onMounted (() => {
472- const savedSize = localStorage .getItem (` pageSize_${props .resource ?.resourceId } ` );
473- if (savedSize ) {
474- const sizeNum = parseInt (savedSize );
475- if (props .resource ?.options ?.listPageSizeOptions ?.includes (sizeNum )) {
476- pageSizeInternal .value = sizeNum ;
477- emits (' update:pageSize' , sizeNum );
478- }
479- }
480- });
481472
482473const checkboxesInternal: Ref <any []> = ref ([]);
483474const pageInput = ref (' 1' );
Original file line number Diff line number Diff line change 173173 @update:records =" getListInner"
174174 @update:pageSize =" (newSize) => { pageSize = newSize; page = 1; }"
175175 :sort =" sort"
176+ :pageSizeOptions =" resolvedPageSizeOptions"
176177 :pageSize =" pageSize"
177178 :totalRows =" totalRows"
178179 :checkboxes =" checkboxes"
@@ -237,6 +238,8 @@ import {
237238import Filters from ' @/components/Filters.vue' ;
238239import { useAdminforth } from ' @/adminforth' ;
239240
241+ const adminforth = useAdminforth ();
242+
240243const filtersShow = ref (false );
241244const { list, alert } = useAdminforth ();
242245const coreStore = useCoreStore ();
@@ -408,12 +411,28 @@ function clearAutoRefresher() {
408411 }
409412}
410413
414+ const resolvedPageSizeOptions = ref <number []>([]);
415+
411416async function init() {
412417
413418 await coreStore .fetchResourceFull ({
414419 resourceId: route .params .resourceId as string
415420 });
416421
422+ const optionsRaw = coreStore .resource ?.options ?.listPageSizeOptions ;
423+
424+ if (typeof optionsRaw === ' function' ) {
425+ resolvedPageSizeOptions .value = await optionsRaw ({
426+ adminUser: coreStore .adminUser ,
427+ adminforth: adminforth
428+ });
429+ } else if (Array .isArray (optionsRaw )) {
430+ resolvedPageSizeOptions .value = optionsRaw ;
431+ } else {
432+ resolvedPageSizeOptions .value = [];
433+ }
434+
435+
417436 syncPageSize ();
418437
419438 isPageLoaded .value = true ;
Original file line number Diff line number Diff line change @@ -478,8 +478,7 @@ export interface AdminForthResourceInputCommon {
478478 * or a function returning them. When set together with `listPageSize`, the page
479479 * size should be one of the values returned here.
480480 */
481- listPageSizeOptions ?: number [ ] ;
482-
481+ listPageSizeOptions ?: number [ ] | ( ( args : { adminUser : any , adminforth : any } ) => number [ ] | Promise < number [ ] > ) ;
483482 /**
484483 * Whether to use virtual scroll in list view.
485484 */
You can’t perform that action at this time.
0 commit comments