Skip to content

Commit 74655a9

Browse files
committed
debounce navigate to start after sort/filter change
1 parent c2d0300 commit 74655a9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/x-data-grid/src/hooks/features/pagination/useGridPaginationModel.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use client';
22
import * as React from 'react';
3+
import debounce from '@mui/utils/debounce';
34
import { RefObject } from '@mui/x-internals/types';
45
import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
5-
import { runIf } from '../../../utils/utils';
66
import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
77
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
88
import { GridPaginationModelApi, GridPaginationState } from './gridPaginationInterfaces';
@@ -277,6 +277,11 @@ export const useGridPaginationModel = (
277277
}
278278
}, [apiRef]);
279279

280+
const debouncedNavigateToStart = React.useMemo(
281+
() => debounce(navigateToStart, 0),
282+
[navigateToStart],
283+
);
284+
280285
/**
281286
* Resets the page only if the active items or quick filter has changed from the last time.
282287
* This is to avoid resetting the page when the filter model is changed
@@ -296,16 +301,16 @@ export const useGridPaginationModel = (
296301
}
297302

298303
previousFilterModel.current = currentActiveFilters;
299-
navigateToStart();
304+
debouncedNavigateToStart();
300305
},
301-
[apiRef, navigateToStart],
306+
[apiRef, debouncedNavigateToStart],
302307
);
303308

304309
useGridEvent(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
305310
useGridEvent(apiRef, 'paginationModelChange', handlePaginationModelChange);
306311
useGridEvent(apiRef, 'rowCountChange', handleRowCountChange);
307-
useGridEvent(apiRef, 'sortModelChange', runIf(!props.paginationModel, navigateToStart));
308-
useGridEvent(apiRef, 'filterModelChange', runIf(!props.paginationModel, handleFilterModelChange));
312+
useGridEvent(apiRef, 'sortModelChange', debouncedNavigateToStart);
313+
useGridEvent(apiRef, 'filterModelChange', handleFilterModelChange);
309314

310315
/**
311316
* EFFECTS

0 commit comments

Comments
 (0)