Shadcn React Table

Search documentation

Search the docs

Tree data

For hierarchical data, provide TanStack Table's getSubRows to tell the table where each row's children live. Expansion turns on automatically.

Tree (sub-rows)Expandable hierarchical data via getSubRows.
GitHub
Dana ReedVP EngineeringEngineering24
Sam LeeEng ManagerEngineering8
Priya RaoSenior EngineerEngineering0
Tom FoxEngineerEngineering0
Nina WellsEng ManagerEngineering6
Omar DiazEngineerEngineering0
Chris ValeVP SalesSales12
Ivy BrooksSales LeadSales4
Ravi ShahAccount ExecSales0

Usage

Return the children array from each row. Set initialState.expanded: true to start fully expanded, and usually disable pagination so the tree isn't split across pages.

tsx
const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  getSubRows: (row) => row.subRows,
  enablePagination: false,
  initialState: {
    expanded: true,
  },
})

return <DataTable table={table} />

Indentation

Use row.depth inside a cell renderer to indent child rows so the hierarchy reads clearly.

From a flat list

APIs often return trees as a flat list with parent ids. Build subRows once with useMemo and pass getSubRows as usual.

Tree from a flat listBuild sub-rows from parent ids.
GitHub
Dana ReedVP Engineering
Sam LeeEng Manager
Priya RaoSenior Engineer
Tom FordEngineer
Ana DiazDesign Lead
Kai WuDesigner
Lee ParkVP Sales
Mia ChenAccount Executive

Loading children on expand

Let rows expand before their children exist with TanStack's getRowCanExpand, and load the children when the row expands (control expanded and watch it in onExpandedChange).

Lazy sub-rowsChildren load when a folder is expanded.
GitHub
Design
Engineering
Sales

Editing tree rows

Editing works at any depth: onEditingRowSave gets the row, and you update the matching node in your nested data.

Editing tree dataEdit rows at any depth of a tree.
GitHub
Row actions
Dana ReedVP Engineering24
Sam LeeEng Manager8
Priya RaoSenior Engineer0
Tom FoxEngineer0
Nina WellsEng Manager6
Omar DiazEngineer0
Chris ValeVP Sales12
Ivy BrooksSales Lead4
Ravi ShahAccount Exec0

Expand-all toggle

The expand column's header toggles every row. Hide it with enableExpandAll: false.