<ReactDataGrid />
offers support for hierarchical data - configure a treeColumn
and make your dataSource
items have a nodes
array with child records.treeColumn
specifies which column will render the tree collapse/expand/loading icons (the icon can be further configured via renderNodeTool
prop).<ReactDataGrid />
as a tree, we refer to rows as nodes
.expandedNodes
prop (this prop is controlled, see defaultExpandedNodes
for uncontrolled version). The value of this prop should be an object - the keys in this object are the ids of the expanded nodes, while the value for each key should be true
.<ReactDataGrid />
will assign a unique id
(see idProperty
) to all nodes based on the path from the root node to the respective node. This id value is built by joining all the parent ids using the /
character (as defined by nodePathSeparator
prop). So, for example, expandedNodes
could look like this for a grid: expandedNodes={ 1: true, 3: true, '3/1': true', '3/2/1': true }
.<ReactDataGrid />
is not compatible with grouping rows.<ReactDataGrid />
.<ReactDataGrid />
is understanding async and leaf nodes.nodes
property defined (so if nodes !== undefined
) it is not a leaf node.nodes === undefined
(the nodes
property name is configurable via nodesProperty
).nodes
property of a tree node is an array, the node is a parent node (even if nodes.length === 0
) and also a synchronous node.nodes
property is equal to null
. In this case, when the user tries to expand the async node, the <ReactDataGrid />
calls the loadNode({ node, nodeProps })
function prop to load the node children. Alternatively, you could specify loadNodeOnce({ node, nodeProps })
to have the grid load the node children and cache them for future re-use.loadNode({ node, nodeProps })
and loadNodeOnce({ node, nodeProps })
should either return an array (or undefined
) or a Promise that resolves to an array (or undefined
).isNodeAsync({ node, nodeProps })
and isNodeLeaf({ node, nodeProps })
props respectively.4.0.26
introduced stickyTreeNodes
treeNestingSize
.onExpandedNodesChange({ expandedNodes })
function prop is called. Before this function being called, you can cancel the expand by returning false
from onNodeExpand
or from onNodeExpandChange
(called in this order). Cancelling a node collapse can be done by returning false
from onNodeCollapse
or from onNodeExpandChange
(called in this order).expandedNodes
, don't forget to update the prop in response to onExpandedNodesChange
being called.