diff --git a/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts b/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts index 9d5b7f8e0aa34..cd5820115381e 100644 --- a/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts +++ b/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts @@ -456,7 +456,7 @@ export const useGridRowSelection = ( let hasChanged = false; currentSelection.forEach((id: GridRowId) => { - if (filteredRowsLookup[id] === false) { + if (filteredRowsLookup[id] !== true) { if (props.keepNonExistentRowsSelected) { return; } diff --git a/packages/x-data-grid/src/tests/rowSelection.DataGrid.test.tsx b/packages/x-data-grid/src/tests/rowSelection.DataGrid.test.tsx index 78d613915b143..8558816616ed2 100644 --- a/packages/x-data-grid/src/tests/rowSelection.DataGrid.test.tsx +++ b/packages/x-data-grid/src/tests/rowSelection.DataGrid.test.tsx @@ -683,6 +683,27 @@ describe(' - Row selection', () => { expect(getSelectedRowIds()).to.deep.equal([0]); }); + // Related to https://github.com/mui/mui-x/issues/14964 + it('should call `onRowSelectionModelChange` when outdated selected rows are removed', () => { + const data = getBasicGridData(4, 2); + const onRowSelectionModelChangeSpy = spy(); + + const { setProps } = render( + , + ); + + setProps({ + rows: data.rows.slice(0, 1), + }); + + expect(onRowSelectionModelChangeSpy.called).to.equal(true); + }); + it('should retain the outdated selected rows when the rows prop changes when keepNonExistentRowsSelected is true', () => { const data = getBasicGridData(10, 2); const onRowSelectionModelChange = spy();