Skip to content

TreeGrid

Data grid with hierarchical rows shown in a tree column. Extends all Grid props.

Import

ts
import { TreeGrid } from '@itsmemyk/react-tree-grid/treegrid'

Props

TreeGrid accepts all Grid props plus these additional ones:

PropTypeDefaultDescription
dataTreeGridRow[]Hierarchical row data (required)
treeColumnIdstringColumn ID that renders the expand toggle
collapsedbooleanfalseStart all nodes collapsed
rootParentstringRoot parent ID for partial tree rendering
dropBehaviour'child' | 'sibling' | 'complex''complex'How dropped rows are inserted
dragExpandbooleanfalseAuto-expand nodes when hovering during drag
groupBystring | string[]Group flat rows by field value
groupAggregateGroupAggregateConfigAggregation config for grouped rows

TreeGridRef (ref)

tsx
import { useRef } from 'react'
import type { TreeGridRef } from '@itsmemyk/react-tree-grid/treegrid'

const ref = useRef<TreeGridRef>(null)

<TreeGrid ref={ref} columns={columns} data={data} treeColumnId="name" />
MethodSignatureDescription
open(id: string) => voidExpand a row
close(id: string) => voidCollapse a row
openAll() => voidExpand all rows
closeAll() => voidCollapse all rows

TreeGridRow

ts
interface TreeGridRow extends GridRow {
  parent?: string        // parent row ID (flat structure)
  items?: TreeGridRow[]  // nested children (nested structure)
  $opened?: boolean      // start expanded
}

Both flat (parent references) and nested (items) data formats are accepted and can be mixed.

Released under the MIT License.