Comments (2)
This error occurs because we have a special logic to remove, from the specified selection model, those rows that are not in the rows
prop. This logic, in the first render, is triggered during the render phrase because it listens to the sortedRowsSet
event.
I tried to fix below this error by not updating the state during the render phase. It's not very elegant because it relays on an effect.
diff --git a/packages/grid/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts b/packages/grid/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts
index baa86964e..5babb09d3 100644
--- a/packages/grid/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts
+++ b/packages/grid/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts
@@ -526,11 +526,17 @@ export const useGridRowSelection = (
[apiRef, handleSingleRowSelection, selectRows, visibleRows.rows, canHaveMultipleSelection],
);
- useGridApiEventHandler(
- apiRef,
- 'sortedRowsSet',
- runIfRowSelectionIsEnabled(removeOutdatedSelection),
- );
+ const [sortedRowsSet, setSortedRowsSet] = React.useState([]);
+
+ const handleSortedRowsSet = React.useCallback((sortedRows) => {
+ setSortedRowsSet(sortedRows);
+ }, []);
+
+ React.useEffect(() => {
+ removeOutdatedSelection();
+ }, [sortedRowsSet, removeOutdatedSelection]);
+
+ useGridApiEventHandler(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(handleSortedRowsSet));
useGridApiEventHandler(apiRef, 'rowClick', runIfRowSelectionIsEnabled(handleRowClick));
useGridApiEventHandler(
apiRef,
diff --git a/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts b/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts
index a5847ddb7..f55a4c1ef 100644
--- a/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts
+++ b/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts
@@ -166,7 +166,7 @@ export const useGridSorting = (
};
});
- apiRef.current.publishEvent('sortedRowsSet');
+ apiRef.current.publishEvent('sortedRowsSet', apiRef.current.state.sorting.sortedRows);
apiRef.current.forceUpdate();
}, [apiRef, logger, props.sortingMode]);
A workaround for now is to enable the keepNonExistentRowsSelected
prop. The drawback is that the selected row count in the footer will include non-existent rows.
from mui-x.
ok keepNonExistentRowsSelected
works for me as an interim solution. I don't think I'll close the issue since there's still work to be done.
from mui-x.
Related Issues (20)
- [data grid] Can paste cell content into non-editable cells HOT 4
- [AdapterDateFns] Error installation latest version of date-fs package HOT 2
- [test] closed Issue workflow HOT 1
- [data grid] Is there a way to use the onClick function of GridToolbarColumnsButton on other component? HOT 6
- [data grid] Skip tab focus on custom cell HOT 10
- [data grid] Quick filter for child table (Master Detail) from parent table HOT 1
- [data grid] Is it possible to expand detail panel on row click or on any other columns HOT 4
- [data grid] onColumnWidthChange called before autosize affects column width HOT 1
- [data grid] row virtualization memory leak HOT 1
- [data grid] Filter Panel Customization HOT 1
- [data grid] How to move checked row from one grid to another grid in MUI Datagrid premium? HOT 5
- [question] DataGrid row virtualization issue, rows not appearing on scroll HOT 5
- [data grid] Uploading files to mui x datagrid making it understand that cell is updated after file upload HOT 4
- [data grid] Hide column icon-separator for column resizable='false' HOT 2
- [pickers] Console error about non-boolean attribute 'focused' when using `DatePicker` / `DateTimePicker` for custom columns in `DataGrid` HOT 4
- [charts] series prop information is missing in PieChart API page HOT 2
- [data grid] Support data visualization with charts HOT 5
- Selecting minutes from clock breaks the DateTimePicker with format prop passed as "MM/DD/YYYY HH:mm" HOT 1
- issue with grid cell selection and pagination HOT 5
- [data grid] GridActionCellItem compiler error, missing properties HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui-x.