Examples › Expanding rows
The rowExpansion
property allows you to define the “row expansion” behavior of the DataTable.
Basic usage
In its most basic usage scenario, the feature only requires specifying the content to be lazily rendered when a row is expanded.
Click on a row to test the behavior:
Specifying collapse properties
Internally, the expanded content is rendered inside a Mantine Collapse component. You can customize the underlying Collapse component like so:
Here is the code for the above example:
Allowing multiple rows to be expanded at once
By default, a single row can be expanded at a certain time. You can override the default behavior like so:
Here is the code for the above example:
Specifying which rows are expandable
You can specify which rows are expandable like so:
Here is the code for the above example:
Specifying which rows are initially expanded
You can specify which rows are initially expanded like so:
Here is the code for the above example:
Always expand all rows
If you want all rows to be locked in their expanded state, just set the row expansion trigger
property to 'always'
:
Here is the code for the above example:
Using collapse() function in row expansion content
Besides the current record, the content
function also receives a collapse
callback that could be used, for instance, in an inline editor like so:
Here is the code for the above example:
Lazy-loading row expansion data
As mentioned above, the content
function is lazily executed when a row is expanded to prevent creating unnecessary DOM elements.
If your row expansion content needs to show data that comes from outside the table records
, you could exploit this behavior to lazy-load it only when a row is expanded:
Here is the code for the above example:
Controlled mode
You can control the row expansion feature by pointing the rowExpansion
/expanded
property to an object containing:
recordIds
→ an array containing the currently expanded record IDsonRecordIdsChange
→ a callback function that gets called when the currently expanded records change
When using the row expansion feature in controlled mode, if you want to prevent the default behavior of toggling the expansion state on click, set the rowExpansion
/trigger
property to 'never'
.
Here is the code for the above example:
Head over to the next example to see how you can abuse the row expansion feature to display nested tables.