Back to elements
ElementData DisplayFree

Tree Table React component

A table whose rows nest, like files in folders: open and close branches with a chevron, parents add up their children (folder sizes), sort any column with folders kept on top, and tick rows with checkboxes that select whole branches.

When to use the Tree Table component

Use Tree Table for data that is both hierarchical and has columns: file browsers, budgets by department, nested categories with counts, bills of materials. Parents can total their children, so people see sums at every level.

For hierarchy without columns, Tree View is lighter; for flat data, use a regular Data Table.

Installation

Add the Tree Table component to your project with the shadcn CLI. It lands in components/tree-table.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add https://reactframe.com/r/tree-table.json

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Props

<TreeTable /> accepts 9 props, all optional.

  • data
    { id: string; name: string; values?: Record<string, string | number>; children?: TreeRow[] }[]
    Default: DEFAULT_DATA
  • columns
    TreeColumn[]
    Default: DEFAULT_COLUMNS
  • nameLabel

    Label of the first (tree) column.

    string
    Default: "Name"
  • defaultExpanded
    string[]
    Default: ["src", "components"]
  • selectable
    boolean
    Default: true
  • defaultSelected

    Ids of selected leaf rows.

    string[]
    Default: []
  • onSelectionChange
    (ids: string[]) => void
  • theme
    "dark" | "light"
    Default: "dark"
  • className
    string

FAQ

How do parent totals work?
Set sum on a numeric column and every parent shows the sum of its children for it, recursively, like folder sizes.
What does ticking a folder do?
It selects every file inside it. Folders show a dash when only some of their files are selected, and onSelectionChange receives the selected leaf ids.
How does sorting behave in a tree?
Rows are sorted within each level, and folders always stay above files, so the structure never breaks apart.

More Data Display components

Chat Bubble
Free
Transfer List
Free
List Group
Free
Organization Chart
Free
Basic Table
Free
Sortable List
Free