Skip to content

TreePlugin

Tree Data Plugin for tbw-grid

Transforms your flat grid into a hierarchical tree view with expandable parent-child relationships. Ideal for file explorers, organizational charts, nested categories, or any data with a natural hierarchy.

import { TreePlugin } from '@toolbox-web/grid/plugins/tree';
OptionTypeDefaultDescription
childrenFieldstring'children'Field containing child array
autoDetectbooleantrueAuto-detect tree structure from data
defaultExpandedbooleanfalseExpand all nodes initially
indentWidthnumber20Indentation per level (pixels)
showExpandIconsbooleantrueShow expand/collapse toggle icons
animationfalse | 'slide' | 'fade''slide'Animation style for expand/collapse
MethodSignatureDescription
expand(nodeId) => voidExpand a specific node
collapse(nodeId) => voidCollapse a specific node
toggle(nodeId) => voidToggle a node’s expanded state
expandAll() => voidExpand all nodes
collapseAll() => voidCollapse all nodes
getExpandedNodes() => Set<string>Get currently expanded node keys
PropertyDefaultDescription
--tbw-tree-toggle-size1.25emToggle icon width
--tbw-tree-indent-widthvar(--tbw-tree-toggle-size)Indentation per level
--tbw-tree-accentvar(--tbw-color-accent)Toggle icon hover color
--tbw-animation-duration200msExpand/collapse animation duration
--tbw-animation-easingease-outAnimation curve
import { queryGrid } from '@toolbox-web/grid';
import { TreePlugin } from '@toolbox-web/grid/plugins/tree';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Name' },
{ field: 'type', header: 'Type' },
{ field: 'size', header: 'Size' },
],
plugins: [new TreePlugin({ childrenField: 'children', indentWidth: 24 })],
};
grid.rows = [
{
id: 1,
name: 'Documents',
type: 'folder',
children: [
{ id: 2, name: 'Report.docx', type: 'file', size: '24 KB' },
],
},
];
new TreePlugin({
defaultExpanded: true,
animation: 'fade', // 'slide' | 'fade' | false
indentWidth: 32,
})
  • TreeConfig for all configuration options
  • FlattenedTreeRow for the flattened row structure

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

PropertyTypeDescription
manifestPluginManifestPlugin manifest - declares owned properties, config rules, and hook priorities.

Plugin manifest - declares owned properties, config rules, and hook priorities.

This is read by the configuration validator to:

  • Validate that required plugins are loaded when their properties are used
  • Execute configRules to detect invalid/conflicting settings
  • Order hook execution based on priority
static override readonly manifest: PluginManifest<MyConfig> = {
ownedProperties: [
{ property: 'myProp', level: 'column', description: 'the "myProp" column property' },
],
configRules: [
{ id: 'myPlugin/conflict', severity: 'warn', message: '...', check: (c) => c.a && c.b },
],
};

detect(rows: unknown): boolean
NameTypeDescription
rowsunknown

expand(key: string): void
NameTypeDescription
keystring

collapse(key: string): void
NameTypeDescription
keystring

toggle(key: string): void
NameTypeDescription
keystring

expandAll(): void

collapseAll(): void

isExpanded(key: string): boolean
NameTypeDescription
keystring

getExpandedKeys(): string[]

getFlattenedRows(): FlattenedTreeRow<TreeRow>[]

getRowByKey(key: string): TreeRow | undefined
NameTypeDescription
keystring

expandToKey(key: string): void
NameTypeDescription
keystring

AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt