DataGrid - Miscellaneous
You can use controlled props to save the <DataGrid /> component props/state and restore them later. In the example below, we demo saving and restoring the column order, column size and sortInfo.
The example below shows how you can render a custom checkbox component (really any component) in a <DataGrid /> configured with a checkbox column for selection.
By specifying a checkboxColumn.renderCheckbox prop, you have a custom render function for all checkboxes (both the header and row checkboxes). Overriding just the header checkbox is done via a check for the cellProps.headerCell boolean flag.
In case you want the default rendering to occur (even if you specify the custom renderCheckbox function), return undefined.
Using the <DataGrid /> you can build an Excel-like experience pretty easily. The example below demonstrates how you can use the Tab key to navigate between cells (arrow keys also work). To enter edit mode, hit Space or Enter.
When using inline-edit in the <DataGrid /> you can retrieve the edit value lazily, by using columns.getEditStartValue. In the snippet bellow, the NAME column retrieves the edit value lazily (with a delay of 250 ms).
The example below shows how you can supress the default editor rendering for a column, and instead render the editor inside the cell contents (in the column render function) - see the COUNTRY column in the example.
When using inline-edit in the <DataGrid /> you can have columns that use their render function to render an already visible editor. In this case, make sure you specify rendersInlineEditor=true for the column. When the column editor is focused, it starts the edit (so it saves the user a double click on the cell in order to start editing). The editor also participates in the edit keyboard navigation flow.
The example below shows how you can export the <DataGrid /> contents as a CSV file. It keeps the sort order and the column order.
By using renderRow(rowProps) or onRenderRow(rowProps) you can attach custom DOM events to grid rows.
The rowProps argument passed to renderRow (and to onRenderRow) contains information about the rowIndex, the row data object and more.
NOTE: If you add an onCllick prop on this rowProps object, make sure you still call the default onClick that rowProps already has (similarly, you should do this will all other event handlers).