Expanding Sub-Rows (Tree Data) Feature Guide
Mantine React Table has support for expanding sub-rows or tree data. This feature is useful for displaying hierarchical data. The sub-rows can be expanded and collapsed by clicking on the expand/collapse icon.
NOTE: This feature is for expanding rows of the same data type. If you want to add expansion of more data for the same row, check out the Detail Panel Feature Guide.
Relevant Table Options
Relevant State Options
# | State Option | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | TanStack Table Expanding Docs | ||||
Enable Expanding Sub-Rows
To enable expanding sub-rows, you must first set the
enableExpanding
table option to true
.However, your data must also be formatted in a way to allow for expanding rows that are in some way related to each other. By default, Mantine React Table will look for a special
subRows
property on each row of your data and treat any array of rows that it finds as the sub-rows for that row. You can customize or override this behavior by passing a custom getSubRows
table option.First Name | Last Name | Address | City | State | |
---|---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky | |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio |
1-2 of 2
Expand All Rows Button
By default, Mantine React Table will show the expand all button in the expand column header. You can disable this by setting the
enableExpandAll
table option to false
.Expanded Rows Pagination Behavior
By default, Mantine React Table will treat expanded sub-rows the same as any other row when it comes to pagination. This means that some expanded rows may be on the next page. You can change this behavior by setting the
paginateExpandedRows
table option to false
.Expanded Leaf Row Filtering Behavior
If you are using the filtering features alongside sub-row features, then there are a few behaviors and customizations you should be aware of.
Filter From Leaf Rows
By default, filtering is done from parent rows down (so if a parent row is filtered out, all of its children will be filtered out as well). Setting the
filterFromLeafRows
table option to true
will cause filtering to be done from leaf rows up (which means parent rows will be kept so long as one of their child, or grand-child, etc. rows pass the filtering).Max Leaf Row Filter Depth
By default, filtering is done for all rows (max depth of 100), no matter if they are root level parent rows or the child leaf rows of a parent row. Setting the
maxLeafRowFilterDepth
table option to 0
will cause filtering to only be applied to the root level parent rows, with all sub-rows remaining unfiltered. Similarly, setting this option to 1 will cause filtering to only be applied to child leaf rows 1 level deep, and so on.This is useful for situations where you want a row's entire child hierarchy to be visible, regardless of the applied filter.
Expand All Rows By Default
You can manage the initial state of the expanded rows with the
expanded
state option in either the initialState
or state
table options.For example, you may want all rows to be expanded by default. To do this, you can simply set the
expanded
state option to true
.Expand | First Name | Last Name | Address | City | State |
---|---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky | |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia | |
Jordane | Homenick | 1234 Brakus Inlet | South Linda | West Virginia | |
Jordan | Clarkson | 4882 Palm Rd | San Francisco | California | |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska | |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio | |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1-2 of 2
Expand Root Rows Only By Default
Here is a slightly more complex initial expanded state example where all the root rows are expanded by default, but none of the sub rows themselves are expanded by default. We just need to find all of the root row ids and set their key in the
expanded
initialState
option to true
.First Name | Last Name | Address | City | State | |
---|---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky | |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia | |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska | |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio | |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1-5 of 5