Overview
TreeDataGrid is a component built on top of DataGrid to add hierarchical row grouping. This implements the Treegrid pattern.
How it works
- The
groupByprop specifies which columns should be used for grouping - The
rowGrouperfunction groups rows by the specified column keys - Group rows are rendered with expand/collapse toggles
- Child rows are nested under their parent groups
- Groups can be expanded/collapsed by clicking the toggle or using keyboard navigation (←, →)
Keyboard Navigation
- → (Right Arrow): Expand a collapsed group row when focused
- ← (Left Arrow): Collapse an expanded group row when focused, or navigate to parent group
Unsupported Props
The followingDataGrid props are not supported in TreeDataGrid:
onFill- Drag-fill is disabled for tree gridsisRowSelectionDisabled- Row selection disabling is not availablerole-TreeDataGridmanages the ARIA rolearia-rowcount-TreeDataGridmanages the ARIA row count
Caveats
- Group columns cannot be rendered under one column
- Group columns are automatically frozen and cannot be unfrozen
- Cell copy/paste does not work on group rows
- Column groups are not supported;
columnsmust beColumn[]
Props
AllDataGridProps are supported except those listed above. Additional props specific to TreeDataGrid:
An array of column definitions. Unlike
DataGrid, column groups are not supported.An array of column keys to group by. The order determines the grouping hierarchy (first key is the top level, second key is nested under the first, etc.).
A function that groups rows by the specified column key. Returns an object where keys are the group values and values are arrays of rows belonging to that group.
A set of group IDs that are currently expanded. Group IDs are generated by
groupIdGetter.Callback triggered when groups are expanded or collapsed.
Function to generate unique IDs for group rows. If not provided, a default implementation is used that concatenates parent and group keys with
__.Default implementation:Note: Unlike
DataGrid, the rowHeight function receives RowHeightArgs<R> which includes a type property to distinguish between regular rows and group rows:Generics
R- Row typeSR- Summary row type (default:unknown)K- Row key type (default:Key)