Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Add section explaining how to keep the selection while filtering (@arminmeh) #15199

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading