From e430b203af8423d22739712a0efd5aa5373659b4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:56:41 +0500 Subject: [PATCH] [DataGrid] Pass reason to `onPaginationModelChange` (@DungTiger) (#15402) Co-authored-by: DungTiger Co-authored-by: Bilal Shafi --- .../pagination/useGridPaginationModel.ts | 50 +++++++++++-------- .../src/models/props/DataGridProps.ts | 5 +- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/packages/x-data-grid/src/hooks/features/pagination/useGridPaginationModel.ts b/packages/x-data-grid/src/hooks/features/pagination/useGridPaginationModel.ts index c482999e44acc..98a015f156127 100644 --- a/packages/x-data-grid/src/hooks/features/pagination/useGridPaginationModel.ts +++ b/packages/x-data-grid/src/hooks/features/pagination/useGridPaginationModel.ts @@ -115,17 +115,20 @@ export const useGridPaginationModel = ( } logger.debug("Setting 'paginationModel' to", paginationModel); - apiRef.current.setState((state) => ({ - ...state, - pagination: { - ...state.pagination, - paginationModel: getDerivedPaginationModel( - state.pagination, - props.signature, - paginationModel, - ), - }, - })); + apiRef.current.setState( + (state) => ({ + ...state, + pagination: { + ...state.pagination, + paginationModel: getDerivedPaginationModel( + state.pagination, + props.signature, + paginationModel, + ), + }, + }), + 'setPaginationModel', + ); }, [apiRef, logger, props.signature], ); @@ -184,17 +187,20 @@ export const useGridPaginationModel = ( ...context.stateToRestore.pagination?.paginationModel, } : gridPaginationModelSelector(apiRef); - apiRef.current.setState((state) => ({ - ...state, - pagination: { - ...state.pagination, - paginationModel: getDerivedPaginationModel( - state.pagination, - props.signature, - paginationModel, - ), - }, - })); + apiRef.current.setState( + (state) => ({ + ...state, + pagination: { + ...state.pagination, + paginationModel: getDerivedPaginationModel( + state.pagination, + props.signature, + paginationModel, + ), + }, + }), + 'stateRestorePreProcessing', + ); return params; }, [apiRef, props.autoPageSize, props.signature], diff --git a/packages/x-data-grid/src/models/props/DataGridProps.ts b/packages/x-data-grid/src/models/props/DataGridProps.ts index f6d1e46b9afa8..b35fa21f220ec 100644 --- a/packages/x-data-grid/src/models/props/DataGridProps.ts +++ b/packages/x-data-grid/src/models/props/DataGridProps.ts @@ -642,7 +642,10 @@ export interface DataGridPropsWithoutDefaultValue void; + onPaginationModelChange?: ( + model: GridPaginationModel, + details: GridCallbackDetails<'pagination'>, + ) => void; /** * Callback fired when the row count has changed. * @param {number} count Updated row count.