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)
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.

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.