@theredhead — Frontend Library - v1.0.0
    Preparing search index...

    Class SortableArrayTreeDatasource<T>

    An in-memory tree datasource that supports sorting via a comparator function.

    When a comparator is applied, the datasource re-derives its visible tree structure from the original data. Nodes are sorted at each level of the tree (root nodes and all children recursively). The underlying tree is never mutated.

    const ds = new SortableArrayTreeDatasource([
    { id: '1', data: { name: 'Beta' }, children: [
    { id: '1.1', data: { name: 'Zebra' } },
    { id: '1.2', data: { name: 'Apple' } },
    ]},
    ]);

    // Sort all levels alphabetically by data.name
    ds.applyComparator((a, b) => a.data.name.localeCompare(b.data.name));

    Type Parameters

    • T = unknown

      The data payload type.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Accessors

    • get allRoots(): TreeNode<T>[]

      The full, unsorted root nodes.

      Useful when consumers need to inspect the original tree structure while a sort is active.

      Returns TreeNode<T>[]

    Methods

    • Applies a comparator function to sort the tree at all levels.

      The comparator is applied recursively to root nodes and all descendants. Pass null or undefined to clear the sort and restore the original insertion order.

      Type Parameters

      Parameters

      • comparator: ((a: U, b: U) => number) | null | undefined

        The comparator function, or null/undefined to clear sorting.

      Returns void

    • Applies a serializable sort expression to the tree.

      The expression is compiled into a tree-node comparator that sorts by node.data properties. Sorting is applied recursively at all levels. Pass null to clear sorting and restore the original insertion order.

      Parameters

      Returns void