Basic grouping
Pass grouping with an array of column ids to useDataGrid to group rows by one or more columns.
Each group is displayed as a group row with the grouped value and the number of rows in the group:
Group rows
A group row displays its label in the cell of the grouping column, for example
Department: Engineering (5). Columns with aggregationFn display their aggregatedCell.
Click anywhere on a group row or press Enter / Space while it is focused to toggle the group.
Set withTintedGroupRows on DataGrid to paint group rows with the striped color:
Interactive grouping
Use controlled grouping state with onGroupingChange to change grouping dynamically. With
withColumnMenu on DataGrid, every column that can be grouped gets Group by this column /
Ungroup items in its header menu:
Active grouping: none
Multi-level grouping
Pass multiple column ids in the grouping array to create nested groups.
The first id is the outermost group:
Aggregation
Add aggregationFn and aggregatedCell to column definitions to display computed values in group rows.
TanStack Table provides built-in aggregation functions, for example sum, mean and count:
Grouping by: department
Totals row
Every column with aggregationFn also gets a cell in the totals row, which is rendered in the
table footer whether or not the grid is grouped. Totals aggregate the filtered rows across all pages.
Built-in aggregations are labelled with the aggregation* labels (Sum, Average, etc.),
custom functions have no label. Use meta.aggregationLabel to set the label and
meta.formatAggregatedValue to format the value:
Custom aggregation
Use constructAggregationFn from TanStack Table to define a custom aggregation function.
It receives the rows and a getValue accessor:
groupedColumnMode
The groupedColumnMode option controls what happens to a column after it is used for grouping.
With 'reorder', grouped columns cannot be reordered while they are grouped,
see Column reorder.
groupedColumnMode: remove
Group selection
With withRowSelection, the checkbox of a group row selects or deselects all rows of the group.
Group rows themselves are never selected, rowSelection contains data row ids only.
The group checkbox is not displayed in single selection mode.
Expand and collapse all groups
Use store.table.toggleAllRowsExpanded() to expand or collapse every group at once.
store.table.getIsAllRowsExpanded() returns the current state:
Controlled grouping
Pass grouping and onGroupingChange to useDataGrid for controlled grouping state.
The state is an array of column ids, the first id is the outermost group:
Cell selection
With withCellSelection, group cells are excluded from ranges. The label cell of a group row is
the keyboard target, Enter / Space toggle the group.