AdaptTable for shadcn

Tree data in shadcn

A tree grid is a different shape from a grouped table: the rows themselves nest, rather than being collected under synthetic headers. Point the table at getChildren or getParentId and it renders the hierarchy.

Children indent under their parent, a chevron opens and closes each branch, and arrow keys walk the tree the way a tree widget should. Expansion is part of the table's state, so it lives in the URL like everything else.

Sorting and filtering apply within the tree rather than flattening it — a branch keeps its shape, and a matching child keeps its ancestors on screen.

The branch toggle carries exactly the class the group toggle carries — one table can hold both, and two disclosure controls that looked different would read as two mechanisms.

The code

import { DataTable } from "@adapttable/shadcn";

export function Org({ people, columns }) {
  return (
    <DataTable
      data={people}
      columns={columns}
      rowKey={(row) => row.id}
      getParentId={(row) => row.managerId}
      treeColumn="name"
      urlKey="org"
    />
  );
}

Install

pnpm add @adapttable/shadcn @adapttable/core

The same feature in the other kits

More shadcn features

Reference: tree-data. More of this kit: AdaptTable for shadcn, or the live demo.