LyteNyte Grid logo for light mode. Links back to the documentation home page.
Tree Data

Tree Overview

Use the tree data source to represent parent-child relationships in hierarchical data.

Info

LyteNyte Grid expects tree data as a nested object. Many grids model hierarchies as arrays with path strings. In LyteNyte Grid, an array with path strings maps to non-uniform row grouping, not tree data.

For array-based hierarchies, see the Client Row Grouping guide. Use tree data for object-based hierarchies, such as nested JSON from a server.

Basic Tree

The useTreeDataSource hook transforms a nested JavaScript object into a row data source. Assign the object to the data property of the useTreeDataSource hook.

The example below shows one such configuration:

const data = {
root: {
name: "root",
kind: "folder",
size: null,
modified: "2026-01-22T09:00:00Z",
"package.json": {
name: "package.json",
kind: "file",
size: 1840,
modified: "2026-01-21T18:12:00Z",
lastEditedBy: "Joseph Allen",
permissions: "rw-r--r--",
},
"package-lock.json": {
name: "package-lock.json",
kind: "file",
size: 92000,
modified: "2026-01-21T18:12:30Z",
lastEditedBy: "Joseph Allen",
permissions: "rw-r--r--",
},
},
};
const ds = useTreeDataSource({
data,
rowGroupDefaultExpansion: true,
});

By default, the hook traverses object properties and creates a branch whenever a property value is itself another object.

The demo below renders a tree from a standard JavaScript object. While the tree data source generates the rows, you must still define the columns. Since this structure allows recursion at any level, the data source treats all rows as group rows.

Basic Tree

Fork code on stack blitzFork code on code sandbox

The remaining guides in this tree data section cover advanced configurations, including custom row creation and data editing.

Next Steps

  • Tree Data: Generate hierarchical rows from nested object data.
  • Tree Sorting: Sort tree rows in ascending or descending order.
  • Tree Editing: Edit tree data nodes using LyteNyte Grid's cell editing capabilities.