Skip to content

useTableTreeData

@astryxdesign/core v0.7.1 · useTableTreeData

The config is a MaybeRefOrGetter, so pass a getter to keep the row meta, the expand-all state, and the toggles live.

Parameters ​

NameTypeDefaultDescription
getRowMeta(item: T) => TableTreeRowMeta | undefined—Structural meta for a visible row: { id, level (0-based), hasChildren, isExpanded }. Return undefined for a row that is not part of the tree.
onToggleItem(item: T) => void—Toggle a row's expansion.
hasExpandableRowsboolean—Whether any row in the dataset is expandable. When false the plugin is a no-op: no expanders, no indent, no tree ARIA.
hasExpandAllControlbooleanfalseShow an expand-all/collapse-all toggle in the tree column header. Requires isAllExpanded plus onExpandAll / onCollapseAll.
isAllExpandedboolean | 'indeterminate'—Aggregate expansion state across every expandable row, driving the header expand-all toggle. true when all are expanded, false when none are, 'indeterminate' when some are.
onExpandAll() => void—Expand every expandable row. Wired to the header control.
onCollapseAll() => void—Collapse every row. Wired to the header control.
indent'sm' | 'md' | 'lg''md'Indent step per level, mapped to the spacing-3 / spacing-4 / spacing-6 tokens.
treeColumnKeystringthe first column no plugin addedColumn that carries the indent + expander. When the key is not found, the first column that did not come from a plugin is used.
hasRowClickExpansionbooleanfalseWhen true, clicking anywhere on an expandable row toggles its expansion, in addition to the chevron. A pointer-only convenience: keyboard and assistive-tech users toggle via the chevron button. Clicks on interactive cell content (buttons, links, form controls) or a text selection do not toggle. Leaf rows stay inert, and it is a no-op on flat data.

Returns ​

FieldTypeDescription
transformColumns(columns: TableColumn<T>[]) => TableColumn<T>[]Wraps the cell renderer of the tree column so it draws the level indent, the chevron, and the cell content. Columns come back untouched while hasExpandableRows is false or no tree column is found.
headerPatch(column: TableColumn<T>) => TableHeaderPatch | nullPuts the expand-all / collapse-all button in front of the tree column header text. Returns null for other columns, when hasExpandAllControl is off, or when the three expand-all fields are missing.
rowPatch(row: T, index: number, columnCount: number) => TableRowPatch | nullSets aria-level (level + 1) and, for rows with children, aria-expanded. With hasRowClickExpansion it also adds the click-to-toggle handler and the astryx-table__clickable class on expandable rows.