DataGrid - Miscellaneous

Miscellaneous - saving and restoring DataGrid state

You can use controlled props to save the <ReactDataGrid /> component props/state and restore them later. In the example below, we demo saving and restoring the column order, column size and sortInfo.

Render custom checkbox header in checkbox column

The example below shows how you can render a custom checkbox component (really any component) in a <ReactDataGrid /> 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.

Excel-like cell navigation and edit

Using the <ReactDataGrid /> 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.

Lazy edit with editors being rendered in cell contents.

When using inline-edit in the <ReactDataGrid /> 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.

Editing using custom already-rendered inline editors

When using inline-edit in the <ReactDataGrid /> 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.

CSV export + custom search-box

The example below shows how you can export the <ReactDataGrid /> contents as a CSV file. It keeps the sort order and the column order.

Attaching custom events to rows

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 onClick 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).

Complex objects - Rendering and sorting columns

This example will show how to implement custom sorting on columns with nested objects.