AdaptTable for shadcn

Column groups in shadcn

A parent with children is a column group. This table has three, two children each, open by default. Collapse one to see its mode. Actions stays ungrouped at the end.

Contact is Name + Role with no collapse options: fold is the chevron. Assignment is Team + Status with collapsedKey: "team". Delivery is Timeline + Budget with collapsedRender ($25,300 for 35 days) and align: "start".

collapsibleColumnGroups arms the toggles. The headers and the chevrons are shadcn.

A group header sits on the thead with the preset's classes, spanning its children, and the toggle is a native button wearing the map; a collapsed stub hides the caption.

The code

import { DataTable, type ColumnInput } from "@adapttable/shadcn";

const columns: ColumnInput<Person>[] = [
  {
    header: "Contact",
    children: [
      { key: "name", header: "Name" },
      { key: "role", header: "Role" },
    ],
  },
  {
    header: "Assignment",
    collapsedKey: "team",
    children: [
      { key: "team", header: "Team" },
      { key: "status", header: "Status" },
    ],
  },
  {
    header: "Delivery",
    align: "start",
    collapsedRender: (row) => row.budget + " for 35 days",
    children: [
      { key: "timeline", header: "Timeline" },
      { key: "budget", header: "Budget" },
    ],
  },
];

export function People({ rows }) {
  return (
    <DataTable
      data={rows}
      columns={columns}
      rowKey={(row) => row.id}
      collapsibleColumnGroups
    />
  );
}

Install

pnpm add @adapttable/shadcn @adapttable/core

The same feature in the other kits

More shadcn features

Reference: column-groups, columns. More of this kit: AdaptTable for shadcn, or the live demo.