Data Grid - Selection
Selection allows the user to select and highlight a number of rows that they can then take action on.
Row selection
Row selection can be performed with a simple mouse click, or using the keyboard shortcuts. The grid supports single and multiple row selection.
Single row selection
Single row selection is enable by default with the DataGrid
component.
For the XGrid
, you need to disable multiple row selection with disableMultipleSelection={true}
.
<DataGrid {...data} />
Multiple row selection
To activate multiple selection, put focus the XGrid
component and hold the CTRL key while selecting rows.
<XGrid {...data} />
<DataGrid checkboxSelection {...data} />
Disable selection on click
You might have interactive content in the cells and need to disable the selection of the row on click. Use the disableClickEventBubbling
option in this case.
<DataGrid
checkboxSelection
{...data}
columns={data.columns.map((column) => ({
...column,
disableClickEventBubbling: true,
}))}
/>
<DataGrid
checkboxSelection
onSelectionModelChange={(newSelection) => {
setSelectionModel(newSelection.selectionModel);
}}
selectionModel={selectionModel}
{...data}
/>
apiRef
The grid exposes a set of methods that enables all of these features using the imperative apiRef.
⚠️ Only use this API when you have no alternative. Always start from the declarative API that the grid exposes.
onSelectionChange
: Callback fired when the selection state of one or multiple rows changes.
🚧 Range selection
⚠️ This feature isn't implemented yet. It's coming.
👍 Upvote issue #208 if you want to see it land faster.
With this feature, you will be able to select ranges of cells across the Grid.