@@ -48,7 +48,7 @@ import { MRT_Localization_ZH_HANS } from 'material-react-table/locales/zh-Hans';
4848import { MRT_Localization_ZH_HANT } from 'material-react-table/locales/zh-Hant' ;
4949import { memo , ReactNode , useEffect , useMemo , useState } from 'react' ;
5050import { useTranslation } from 'react-i18next' ;
51- import { getTablesRowsPerPage } from '../../../helpers/tablesRowsPerPage' ;
51+ import { getTablesRowsPerPage , setTablesRowsPerPage } from '../../../helpers/tablesRowsPerPage' ;
5252import { useShortcut } from '../../../lib/useShortcut' ;
5353import { useURLState } from '../../../lib/util' ;
5454import { useSettings } from '../../App/Settings/hook' ;
@@ -203,9 +203,11 @@ export default function Table<RowItem extends Record<string, any>>({
203203
204204 const storeRowsPerPageOptions = useSettings ( 'tableRowsPerPageOptions' ) ;
205205 const rowsPerPageOptions = rowsPerPage || storeRowsPerPageOptions ;
206- const defaultRowsPerPage = useMemo ( ( ) => getTablesRowsPerPage ( rowsPerPageOptions [ 0 ] ) , [ ] ) ;
207- const [ pageSize , setPageSize ] = useURLState ( shouldReflectInURL ? 'perPage' : '' , {
206+ const defaultRowsPerPage = getTablesRowsPerPage ( rowsPerPageOptions [ 0 ] ) ;
207+
208+ const [ pageSize , setPageSize ] = useURLState ( 'perPage' , {
208209 defaultValue : defaultRowsPerPage ,
210+ hideDefault : false ,
209211 prefix,
210212 } ) ;
211213
@@ -272,6 +274,8 @@ export default function Table<RowItem extends Record<string, any>>({
272274 const pagination = updater ( { pageIndex : Number ( page ) - 1 , pageSize : Number ( pageSize ) } ) ;
273275 setPage ( pagination . pageIndex + 1 ) ;
274276 setPageSize ( pagination . pageSize ) ;
277+ // Persist the rows per page setting
278+ setTablesRowsPerPage ( pagination . pageSize ) ;
275279 } ,
276280 onGlobalFilterChange : setGlobalFilter ,
277281 renderToolbarInternalActions : props => {
@@ -285,27 +289,21 @@ export default function Table<RowItem extends Record<string, any>>({
285289 }
286290 return null ;
287291 } ,
288- initialState : useMemo (
289- ( ) => ( {
290- density : 'compact' ,
291- globalFilter : globalFilter || '' ,
292- ...( tableProps . initialState ?? { } ) ,
293- } ) ,
294- [ tableProps . initialState , globalFilter ]
295- ) ,
296- state : useMemo (
297- ( ) => ( {
298- ...( tableProps . state ?? { } ) ,
299- columnOrder,
300- pagination : {
301- pageIndex : page - 1 ,
302- pageSize : pageSize ,
303- } ,
304- globalFilter,
305- ...( globalFilter ? { showGlobalFilter : true } : { } ) ,
306- } ) ,
307- [ tableProps . state , columnOrder , page , pageSize , globalFilter ]
308- ) ,
292+ initialState : {
293+ density : 'compact' ,
294+ globalFilter : globalFilter || '' ,
295+ ...( tableProps . initialState ?? { } ) ,
296+ } ,
297+ state : {
298+ ...( tableProps . state ?? { } ) ,
299+ columnOrder,
300+ pagination : {
301+ pageIndex : page - 1 ,
302+ pageSize : pageSize ,
303+ } ,
304+ globalFilter,
305+ ...( globalFilter ? { showGlobalFilter : true } : { } ) ,
306+ } ,
309307 positionActionsColumn : 'last' ,
310308 layoutMode : 'grid' ,
311309 // Need to provide our own empty message
0 commit comments