I have a Material-UI DataGrid component, and I want it to reset pagination on sorting (see code below).
import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
const Table: React.FC<Readonly<{}>> = () => {
return (
<div>
<DataGrid
onSortModelChange={() => {
// <------------------------ Here I want to reset pagination on sort
}}
/>
</div>
);
};
export default Table;
Solution (use the useGridApiRef)
useGridApiReffrom@mui/x-data-gridapiRef(by invoking theuseGridApiReffunction)apiRef(in theDataGridcomponent)restorePaginationStatefunction.apiRef.current.exportState();will fetch the current state.apiRef.current.restoreState();will set the new state.restorePaginationStatefunction ononSortModelChangeevents.