Global

Methods

addNodeUnderParent(treeDatanon-null, newNodenon-null, parentKey, getNodeKeynon-null, ignoreCollapsedopt, expandParentopt, addAsFirstChildopt) → {Object|Array.<Object>|number}

Adds the node to the specified parent and returns the resulting treeData.

Parameters:
Name Type Attributes Description
treeData Array.<Object>
newNode Object

The node to insert

parentKey number | string

The key of the to-be parentNode of the node

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

expandParent boolean <optional>

If true, expands the parentNode specified by parentPath

addAsFirstChild boolean <optional>

If true, adds new node as first child of tree

Source:
Returns:
  • result

    Type
    Object
  • result.treeData - The updated tree data

    Type
    Array.<Object>
  • result.treeIndex - The tree index at which the node was inserted

    Type
    number

changeNodeAtPath(treeDatanon-null, path, newNode, getNodeKeynon-null, ignoreCollapsedopt) → {Array.<Object>}

Replaces node at path with object, or callback-defined object

Parameters:
Name Type Attributes Description
treeData Array.<Object>
path Array.<number> | Array.<string>

Array of keys leading up to node to be changed

newNode function | any

Node to replace the node at the path with, or a function producing the new node

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

Source:
Returns:

changedTreeData - The changed tree data

Type
Array.<Object>

find(getNodeKeynon-null, treeDatanon-null, searchQuery, searchMethodnon-null, searchFocusOffsetnullable, expandAllMatchPathsopt, expandFocusMatchPathsopt) → {Array.<Object>|Array.<Object>}

Find nodes matching a search query in the tree,

Parameters:
Name Type Attributes Description
getNodeKey function

Function to get the key from the nodeData and tree index

treeData Array.<Object>

Tree data

searchQuery string | number

Function returning a boolean to indicate whether the node is a match or not

searchMethod function

Function returning a boolean to indicate whether the node is a match or not

searchFocusOffset number <nullable>

The offset of the match to focus on (e.g., 0 focuses on the first match, 1 on the second)

expandAllMatchPaths boolean <optional>

If true, expands the paths to any matched node

expandFocusMatchPaths boolean <optional>

If true, expands the path to the focused node

Source:
Returns:
  • matches - An array of objects containing the matching nodes, their paths and treeIndexs

    Type
    Array.<Object>
  • treeData - The original tree data with all relevant nodes expanded. If expandAllMatchPaths and expandFocusMatchPaths are both false, it will be the same as the original tree data.

    Type
    Array.<Object>

getDepth(nodenon-null, depthnullable) → {number}

Get the maximum depth of the children (the depth of the root node is 0).

Parameters:
Name Type Attributes Description
node Object

Node in the tree

depth number <nullable>

The current depth

Source:
Returns:

maxDepth - The deepest depth in the tree

Type
number

getFlatDataFromTree(treeDatanon-null, getNodeKeynon-null, ignoreCollapsedopt)

Get tree data flattened.

Parameters:
Name Type Attributes Description
treeData Array.<Object>

Tree data

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

Source:
Returns:

getNodeAtPath(treeDatanon-null, path, getNodeKeynon-null, ignoreCollapsedopt) → {Object|null}

Gets the node at the specified path

Parameters:
Name Type Attributes Description
treeData Array.<Object>
path Array.<number> | Array.<string>

Array of keys leading up to node to be deleted

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

Source:
Returns:

nodeInfo - The node info at the given path, or null if not found

Type
Object | null

getNodeDataAtTreeIndexOrNextIndex()

Performs a depth-first traversal over all of the node descendants, incrementing currentIndex by 1 for each

Source:

getTreeFromFlatData(flatDatanon-null, getKeyopt, non-null, getParentKeyopt, non-null, rootKey) → {Array.<Object>}

Generate a tree structure from flat data.

Parameters:
Name Type Attributes Description
flatData Array.<Object>
getKey function <optional>

Function to get the key from the nodeData

getParentKey function <optional>

Function to get the parent key from the nodeData

rootKey string | number

The value returned by getParentKey that corresponds to the root node. For example, if your nodes have id 1-99, you might use rootKey = 0

Source:
Returns:

treeData - The flat data represented as a tree

Type
Array.<Object>

getVisibleNodeCount(treeDatanon-null) → {number}

Count all the visible (expanded) descendants in the tree data.

Parameters:
Name Type Description
treeData Array.<Object>

Tree data

Source:
Returns:

count

Type
number

getVisibleNodeInfoAtIndex(treeDatanon-null, targetIndexnon-null, getNodeKeynon-null)

Get the th visible node in the tree data.

Parameters:
Name Type Description
treeData Array.<Object>

Tree data

targetIndex number

The index of the node to search for

getNodeKey function

Function to get the key from the nodeData and tree index

Source:
Returns:

insertNode(treeDatanon-null, depthnon-null, minimumTreeIndexnon-null, newNodenon-null, ignoreCollapsedopt, expandParentopt, getNodeKeynon-null) → {Object|Array.<Object>|number|Array.<number>|Array.<string>|Object}

Insert a node into the tree at the given depth, after the minimum index

Parameters:
Name Type Attributes Description
treeData Array.<Object>

Tree data

depth number

The depth to insert the node at (the first level of the array being depth 0)

minimumTreeIndex number

The lowest possible treeIndex to insert the node at

newNode Object

The node to insert into the tree

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

expandParent boolean <optional>

If true, expands the parent of the inserted node

getNodeKey function

Function to get the key from the nodeData and tree index

Source:
Returns:
  • result

    Type
    Object
  • result.treeData - The tree data with the node added

    Type
    Array.<Object>
  • result.treeIndex - The tree index at which the node was inserted

    Type
    number
  • result.path - Array of keys leading to the node location after insertion

    Type
    Array.<number> | Array.<string>
  • result.parentNode - The parent node of the inserted node

    Type
    Object

isDescendant(oldernon-null, youngernon-null) → {boolean}

Check if a node is a descendant of another node.

Parameters:
Name Type Description
older Object

Potential ancestor of younger node

younger Object

Potential descendant of older node

Source:
Returns:
Type
boolean

map(treeDatanon-null, getNodeKeynon-null, callback, ignoreCollapsedopt) → {Array.<Object>}

Perform a depth-first transversal of the descendants and make a change to every node in the tree

Parameters:
Name Type Attributes Description
treeData Array.<Object>

Tree data

getNodeKey function

Function to get the key from the nodeData and tree index

callback function

Function to call on each node

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

Source:
Returns:

changedTreeData - The changed tree data

Type
Array.<Object>

mapDescendants(args) → {number|false}

Perform a change on the given node and all its descendants, traversing the tree depth-first

Parameters:
Name Type Description
args Object

Function parameters

Properties
Name Type Attributes Description
callback function

Function to call on each node

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean

Ignore children of nodes without expanded set to true

isPseudoRoot boolean <optional>

If true, this node has no real data, and only serves as the parent of all the nodes in the tree

node Object

A tree node

parentNode Object <optional>

The parent node of node

currentIndex number

The treeIndex of node

path Array.<number> | Array.<string>

Array of keys leading up to node to be changed

lowerSiblingCounts Array.<number>

An array containing the count of siblings beneath the previous nodes in this path

Source:
Returns:

nextIndex - Index of the next sibling of node, or false if the walk should be terminated

Type
number | false

removeNode(treeDatanon-null, path, getNodeKeynon-null, ignoreCollapsedopt) → {Object|Array.<Object>|Object|number}

Removes the node at the specified path and returns the resulting treeData.

Parameters:
Name Type Attributes Description
treeData Array.<Object>
path Array.<number> | Array.<string>

Array of keys leading up to node to be deleted

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

Source:
Returns:
  • result

    Type
    Object
  • result.treeData - The tree data with the node removed

    Type
    Array.<Object>
  • result.node - The node that was removed

    Type
    Object
  • result.treeIndex - The previous treeIndex of the removed node

    Type
    number

removeNodeAtPath(treeDatanon-null, path, getNodeKeynon-null, ignoreCollapsedopt) → {Array.<Object>}

Removes the node at the specified path and returns the resulting treeData.

Parameters:
Name Type Attributes Description
treeData Array.<Object>
path Array.<number> | Array.<string>

Array of keys leading up to node to be deleted

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

Source:
Returns:

changedTreeData - The tree data with the node removed

Type
Array.<Object>

toggleExpandedForAll(treeDatanon-null, expandednullable) → {Array.<Object>}

Expand or close every node in the tree

Parameters:
Name Type Attributes Description
treeData Array.<Object>

Tree data

expanded boolean <nullable>

Whether the node is expanded or not

Source:
Returns:

changedTreeData - The changed tree data

Type
Array.<Object>

walk(treeDatanon-null, getNodeKeynon-null, callback, ignoreCollapsedopt)

Walk descendants depth-first and call a callback on each

Parameters:
Name Type Attributes Description
treeData Array.<Object>

Tree data

getNodeKey function

Function to get the key from the nodeData and tree index

callback function

Function to call on each node

ignoreCollapsed boolean <optional>

Ignore children of nodes without expanded set to true

Source:
Returns:

void

walkDescendants(args) → {number|false}

Walk all descendants of the given node, depth-first

Parameters:
Name Type Description
args Object

Function parameters

Properties
Name Type Attributes Description
callback function

Function to call on each node

getNodeKey function

Function to get the key from the nodeData and tree index

ignoreCollapsed boolean

Ignore children of nodes without expanded set to true

isPseudoRoot boolean <optional>

If true, this node has no real data, and only serves as the parent of all the nodes in the tree

node Object

A tree node

parentNode Object <optional>

The parent node of node

currentIndex number

The treeIndex of node

path Array.<number> | Array.<string>

Array of keys leading up to node to be changed

lowerSiblingCounts Array.<number>

An array containing the count of siblings beneath the previous nodes in this path

Source:
Returns:

nextIndex - Index of the next sibling of node, or false if the walk should be terminated

Type
number | false