Turns hierarchical data into tree rows for a tree table. Pass the result as rows to TableFactory.createTableModel – the factory then creates an AreaModelTree; the first column shows the arrows.

Example

interface Node { label: string; total: number; children?: Node[] }

const rows = TreeFactory.buildTreeRows<Node>(nodes, {
childrenProperty: "children",
expanded: (row, deep) => deep === 0 // open only the first level
});
const tableModel = TableFactory.createTableModel({
rows,
columnDefs: [new ColumnDef("label", "Name", px300, bodyLeft), new ColumnDef("total", "Total", px120, allRight)]
});

See

Training: Tree table with checkboxes

Hierarchy

  • TreeFactory

Constructors

Methods

  • Appends the child rows of data (recursively) to parent – used by buildTreeRows. No row deeper than deepMaxLimit is created: the children of a row at depth deepMaxLimit are skipped with a console warning.

    Type Parameters

    • T

    Parameters

    • data: T

      the object whose children are added

    • childrenProperty: string = "children"

      name of the children property (default "children")

    • parent: TreeRowIf<T> = ...

      the tree row of data (default: a new, expanded top-level row)

    • deep: number = 0

      depth of parent (0 = top level)

    • deepMaxLimit: number = 12

      maximum depth of a created row (default 12)

    • expanded: boolean | TreeRowExpandedFn<T> = true

      expanded state of the new rows (default true)

    Returns TreeRowIf<T>

    parent

    Example

    const root = TreeFactory.buildTreeRow<OrderNode>(nodes[0], "children");
    console.log(root.children?.length);
  • Builds tree rows (input for TableFactory.createTableModel({ rows })) from nested objects.

    Type Parameters

    • T

    Parameters

    • data: T[]

      the top-level objects

    • childrenPropertyOrOptions: string | TreeFactoryOptions<T> = "children"

      name of the children property (default "children") or TreeFactoryOptions

    • deepMaxLimit: number = 12

      maximum depth of a row, 0 = top level only (default 12; ignored when options are passed)

    • expanded: boolean | TreeRowExpandedFn<T> = true

      expanded state of the rows (default true; ignored when options are passed)

    Returns TreeRowIf<T>[]

    Example

    const rows = TreeFactory.buildTreeRows<OrderNode>(data, { childrenProperty: "children", expanded: false });