ProGridSign in

Features

Tree data

Show rows that already have a hierarchy — a folder tree, an org chart, a work breakdown — with an indent and a chevron per level, filters that keep the path to a match, and sorting within each parent.

Nested rows

Pass treeData.getSubRows and the grid reads the hierarchy off the rows themselves. The tree column gets an indent per level and a chevron on rows with children; every other column shows the row's own values, parents included. Filtering keeps the parents of a match so the path to it stays readable, and sorting orders siblings within their parent rather than flattening the tree.

<ProGrid
  columns={columns}
  data={items}                       // nested: each item may carry children
  getRowId={(item) => item.id}
  treeData={{
    getSubRows: (item) => item.children,
    treeColumn: "title",             // defaults to the first column
    initialExpandDepth: 1,           // 0 shows roots only; "all" opens everything
  }}
/>
Live demo

A work breakdown

Epics hold stories, stories hold tasks. Open a level, sort by points, or filter down to one task.

import { useRef } from "react"
import { ProGrid, type ProColumnDef, type ProGridHandle } from "@/components/pro-grid"

function StatusCell({ value }: { value: unknown }) {
  const status = String(value)
  return <span className={`order-status order-status--${status.toLowerCase().replaceAll(" ", "-")}`}>{status}</span>
}

type WorkItem = {
  id: string
  title: string
  kind: "Epic" | "Story" | "Task"
  owner: string
  estimate: number
  status: "On track" | "At risk" | "Delayed" | "Complete"
  children?: WorkItem[]
}

const workItems: WorkItem[] = [
  {
    id: "EP-1", title: "Checkout redesign", kind: "Epic", owner: "Ana", estimate: 34, status: "On track",
    children: [
      {
        id: "ST-11", title: "Address step", kind: "Story", owner: "Bo", estimate: 13, status: "On track",
        children: [
          { id: "T-111", title: "Postcode lookup", kind: "Task", owner: "Bo", estimate: 5, status: "Complete" },
          { id: "T-112", title: "Validation copy", kind: "Task", owner: "Cy", estimate: 3, status: "On track" },
          { id: "T-113", title: "Saved addresses", kind: "Task", owner: "Bo", estimate: 5, status: "At risk" },
        ],
      },
      {
        id: "ST-12", title: "Payment step", kind: "Story", owner: "Dee", estimate: 21, status: "At risk",
        children: [
          { id: "T-121", title: "Card form", kind: "Task", owner: "Dee", estimate: 8, status: "On track" },
          { id: "T-122", title: "Wallet buttons", kind: "Task", owner: "Eli", estimate: 8, status: "Delayed" },
          { id: "T-123", title: "3-D Secure", kind: "Task", owner: "Dee", estimate: 5, status: "At risk" },
        ],
      },
    ],
  },
  {
    id: "EP-2", title: "Search relevance", kind: "Epic", owner: "Fay", estimate: 21, status: "Delayed",
    children: [
      {
        id: "ST-21", title: "Synonyms", kind: "Story", owner: "Fay", estimate: 8, status: "Complete",
        children: [
          { id: "T-211", title: "Curate list", kind: "Task", owner: "Gus", estimate: 3, status: "Complete" },
          { id: "T-212", title: "Index rebuild", kind: "Task", owner: "Fay", estimate: 5, status: "Complete" },
        ],
      },
      { id: "ST-22", title: "Typo tolerance", kind: "Story", owner: "Gus", estimate: 13, status: "Delayed" },
    ],
  },
  { id: "EP-3", title: "Accessibility audit", kind: "Epic", owner: "Hal", estimate: 8, status: "On track" },
]

const workItemColumns: ProColumnDef<WorkItem>[] = [
  { accessorKey: "title", header: "Item", size: 260, meta: { label: "Item", type: "string" } },
  { accessorKey: "id", header: "Key", size: 90, meta: { label: "Key", type: "string" } },
  {
    accessorKey: "kind",
    header: "Kind",
    size: 90,
    meta: { label: "Kind", type: "string", filterOptions: ["Epic", "Story", "Task"] },
  },
  { accessorKey: "owner", header: "Owner", size: 100, meta: { label: "Owner", type: "string" } },
  {
    accessorKey: "status",
    header: "Status",
    size: 110,
    cell: ({ getValue }) => <StatusCell value={getValue()} />,
    meta: { label: "Status", type: "string", filterOptions: ["On track", "At risk", "Delayed", "Complete"] },
  },
  { accessorKey: "estimate", header: "Points", size: 80, meta: { label: "Points", type: "number", align: "right" } },
]

/**
 * A work breakdown as a tree: epics hold stories, stories hold tasks. The rows
 * arrive already nested, so `getSubRows` just reads `children`.
 */
export function TreeDataDocsDemo() {
  const gridRef = useRef<ProGridHandle<WorkItem>>(null)

  return (
    <>
      <div className="docs-demo__status" aria-live="polite">
        <span>Filter for &quot;wallet&quot; and the epic and story above it stay.</span>
        <span className="flex gap-3">
          <button type="button" className="underline" onClick={() => gridRef.current?.expandTree("all")}>Expand all</button>
          <button type="button" className="underline" onClick={() => gridRef.current?.collapseTree()}>Collapse all</button>
        </span>
      </div>
      <ProGrid<WorkItem>
        ref={gridRef}
        columns={workItemColumns}
        data={workItems}
        getRowId={(row) => row.id}
        height={400}
        treeData={{ getSubRows: (row) => row.children, initialExpandDepth: 1 }}
        rowSelection={false}
        toolbar={{ pivot: false, chart: false }}
        title="Q3 delivery plan"
      />
    </>
  )
}
Filter for "wallet" and the epic and story above it stay.

Q3 delivery plan

Item
Key
Kind
Owner
Status
Points
15 rows

Rows that arrive flat

nestByPath turns rows carrying a path into the nested shape, creating a filler row for any level no row claims. It is pure and exported from the server entry too, so an API route can nest before it responds.

import { nestByPath } from "@/components/pro-grid"

// Rows from an API often arrive flat, each with its path.
const flat = [
  { path: ["Engineering", "Platform", "Ana"], name: "Ana", headcount: 1 },
  { path: ["Engineering", "Platform"], name: "Platform", headcount: 12 },
  { path: ["Sales", "Cy"], name: "Cy", headcount: 1 },
]

// Every prefix becomes a node; one nobody claims ("Sales") is made by the filler.
const tree = nestByPath(flat, (r) => r.path, (path) => ({ path: [...path], name: path.at(-1)!, headcount: 0 }))

Expansion

initialExpandDepth opens the first levels when rows first arrive; after that the reader's own opening and closing is kept across data changes, because expansion is keyed by row id. The handle opens or closes the whole tree:

grid.current?.expandTree(2)      // open two levels
grid.current?.expandTree("all")
grid.current?.collapseTree()