Skip to content

Commit

Permalink
[docs] Add section explaining how to keep the selection while filteri…
Browse files Browse the repository at this point in the history
…ng (#15185)

Signed-off-by: Armin Mehinovic <[email protected]>
Co-authored-by: Sycamore <[email protected]>
  • Loading branch information
arminmeh and samuelsycamore authored Oct 30, 2024
1 parent b204906 commit c75774c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/data/data-grid/row-selection/KeepNonExistentRowsSelected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { DataGrid, GridToolbar } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

export default function KeepNonExistentRowsSelected() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
checkboxSelection
disableRowSelectionOnClick
keepNonExistentRowsSelected
slots={{
toolbar: GridToolbar,
}}
slotProps={{
toolbar: {
showQuickFilter: true,
},
}}
/>
</div>
);
}
30 changes: 30 additions & 0 deletions docs/data/data-grid/row-selection/KeepNonExistentRowsSelected.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { DataGrid, GridToolbar } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

export default function KeepNonExistentRowsSelected() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
checkboxSelection
disableRowSelectionOnClick
keepNonExistentRowsSelected
slots={{
toolbar: GridToolbar,
}}
slotProps={{
toolbar: {
showQuickFilter: true,
},
}}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<DataGrid
{...data}
checkboxSelection
disableRowSelectionOnClick
keepNonExistentRowsSelected
slots={{
toolbar: GridToolbar,
}}
slotProps={{
toolbar: {
showQuickFilter: true,
},
}}
/>
7 changes: 7 additions & 0 deletions docs/data/data-grid/row-selection/row-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ In the demo below only rows with quantity above 50,000 can be selected:

{{"demo": "DisableRowSelection.js", "bg": "inline"}}

## Row selection with filtering

By default, when the rows are filtered the selection is cleared from the rows that don't meet the filter criteria.
To keep those rows selected even when they're not visible, set the `keepNonExistentRowsSelected` prop.

{{"demo": "KeepNonExistentRowsSelected.js", "bg": "inline"}}

## Controlled row selection

Use the `rowSelectionModel` prop to control the selection.
Expand Down

0 comments on commit c75774c

Please sign in to comment.