DataGrid - Row details
The <DataGrid /> supports showing row details via expanded rows. In order to enable expanded rows, make sure to specify arowExpandHeight and the renderRowDetails({ data, rowIndex, ... }) function prop, which will be used to render the details for expanded rows. When enabling row expand, the <DataGrid /> will now have two possible row heights: unexpanded (collapsed) rows will have the height specified by rowHeight, while expanded rows will have their size specified by rowExpandHeight.
Expanded rows are managed via the expandedRows prop (this prop is controlled, see defaultExpandedRows for uncontrolled version). The value of this prop should be an object - the keys in this object are the ids of the expanded rows, while the value for each key should be true.
expandedRows can also be true, which means all rows should be rendered as expanded - however, we still need the ability to specify that some of the rows should be collapsed - this is achieved via collapsedRows (controlled; see defaultExpandedRows for uncontrolled alternative).
The example below shows a basic example of the row details expand functionality
For rendering row details in expanded rows, use the renderRowDetails({ data, rowIndex, ... }) function prop. It is called for you with an object as a first argument - the object has the following properties:
  • data - the data item corresponding to the current expanded row
  • rowSelected - specifies if the current row is selected
  • rowActive - specifies if the current row is active
  • rowId - the value of the idProperty for the current row data object
  • toggleRowExpand - you can call this function with no arguments to collapse the current row
  • dataSource - a reference to the current dataSource array that the <DataGrid /> displays
As documented above, the renderRowDetails function prop gives the developer access to a lot of information about the row being rendered, which makes it really flexible and easy to use.
When expanded rows are enabled in a grid instance, the column render function is called with arguments that contain information about the expanded state of the row, and with functions that can be used to change the row expanded state - see columns.render for details.
Single expand - the ability to only expand one row (when another one is expanded, it collapses the other expanded row) - is achieved via multiRowExpand=false. By default the <DataGrid /> is configured to allow multiple rows to be expanded at the same time.
Another important feature is the ability to configure (or hide) the row expand column that's automatically added when row expand is enabled. This is accomplished by specifying the rowExpandColumn prop on the <DataGrid />.
rowExpandColumn=false hides the row expand column.
rowExpandColumn can also be an object (a column configuration object), so you can specify custom rowExpandColumn.render, rowExpandColumn.header, etc render functions. All properties available for normal columns are also available here.
The expanded rows can be specified via controlled or uncontrolled props. The same goes for collapsed rows, they can be controlled or uncontrolled props. In both cases, there are a number of callback props being called when new rows are expanded or collapsed:
  • onRowExpand - called when a single row is expanded. Returning false from this function will prevent expanding the row.
  • onRowCollapse - called when a single row is collapsed. Returning false from this function will prevent collapsing the row.
  • onRowExpandChange - called when a single row is collapsed or expanded. Returning false from this function will prevent collapsing or expanding the row.
  • onExpandedRowsChange - unlike all of the above, this function is called for both single row expand/collapse, as well as for bulk actions, like calling collapseAllRows or expandAllRows.
When using controlled props, like expandedRows or collapsedRows to control which rows are expanded or collapsed, make sure you update their values as a result of user interaction, which triggers the callback props described above (eg onExpandedRowsChange).
You can specify which rows should not be expandable, via the isRowExpandable function prop, which gives you a lot of flexibility to decide which rows should not be expandable.
As an alternative, in order to specify unexpandable rows, you can also use unexpandableRows - it's not as flexible as isRowExpandable, but it can be a bit more performant.
For a better experience, the row details can be integrated with the ScrollContainer, to have the same scroller as the <DataGrid />. See the example below for details.