Skip to content

Commit

Permalink
Fix the datagrid remounting when columns change (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Jul 20, 2023
1 parent ac2e2d3 commit 2ff2231
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions packages/toolpad-components/src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,8 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
apiRef.current.updateColumns(columns);
}, [apiRef, columns]);

// The grid doesn't update when the getRowId or columns properties change, so it needs to be remounted
// TODO: remove columns from this equation once https://github.com/mui/mui-x/issues/5970 gets resolved
const gridKey = React.useMemo(
() => [getObjectKey(getRowId), getObjectKey(columns)].join('::'),
[getRowId, columns],
);
// The grid doesn't update when the getRowId property changes, so it needs to be remounted
const gridKey = React.useMemo(() => getObjectKey(getRowId), [getRowId]);

const error: Error | null = errorProp ? errorFrom(errorProp) : null;

Expand All @@ -481,9 +477,9 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
>
<DataGridPro
apiRef={apiRef}
components={{
Toolbar: hideToolbar ? null : GridToolbar,
LoadingOverlay: SkeletonLoadingOverlay,
slots={{
toolbar: hideToolbar ? null : GridToolbar,
loadingOverlay: SkeletonLoadingOverlay,
}}
onColumnResize={handleResize}
onColumnOrderChange={handleColumnOrderChange}
Expand Down

0 comments on commit 2ff2231

Please sign in to comment.