-
-
Notifications
You must be signed in to change notification settings - Fork 39
Functions: Tree
- addChildNodes
- appendChildNode
- checkNode
- clear
- closeNode
- filter
- flattenChildNodes
- flattenNode
- getChildNodes
- getNodeById
- getNodeFromPoint
- getOpenNodes
- getRootNode
- getSelectedIndex
- getSelectedNode
- insertNodeAfter
- insertNodeBefore
- loadData
- moveNodeTo
- openNode
- removeChildNodes
- removeNode
- scrollToNode
- scrollTop
- selectNode
- swapNodes
- toggleNode
- toString
- unfilter
- update
- updateNode
Adds an array of new child nodes to a parent node at the specified index.
- newNodes (Array): An array of new child nodes.
- [index] (number): The 0-based index of where to insert the child node.
- [parentNode] (Node): The Node object that defines the parent node.
(boolean): Returns true on success, false otherwise.
Adds a new child node to the end of the list of children of a specified parent node.
- If the parent is null or undefined, inserts the child at the specified index in the top-level.
- If the parent has children, the method adds the child as the last child.
- If the parent does not have children, the method adds the child to the parent.
- newNode (Object): The new child node.
- parentNode (Node): The Node object that defines the parent node.
(boolean): Returns true on success, false otherwise.
Checks or unchecks the node.
- node (Node): The Node object.
- [checked] (boolean): Whether to check or uncheck the node. If not specified, it will toggle between checked and unchecked state.
(boolean): Returns true on success, false otherwise.
state.checked | state.indeterminate | description |
---|---|---|
false | false | The node and all of its children are unchecked. |
true | false | The node and all of its children are checked. |
true | true | The node will appear as indeterminate when the node is checked and some (but not all) of its children are checked. |
tree.checkNode(node);// toggle checked and unchecked state
tree.checkNode(node, true); // checked=true, indeterminate=false
tree.checkNode(node, false); // checked=false, indeterminate=false
Clears the tree.
Closes a node to hide its children.
- node (Node): The Node object.
- [options={}] (Object): The options object.
- [options.silent=false] (boolean): Sets true to prevent "closeNode" event from being triggered.
(boolean): Returns true on success, false otherwise.
Filters nodes. Use a string or a function to test each node of the tree. Otherwise, it will render nothing after filtering (e.g. tree.filter()
, tree.filter(null)
, tree.flter(0)
, tree.filter({})
, etc.).
- predicate (string|function): A keyword string, or a function to test each node of the tree. If the predicate is an empty string, all nodes will be filtered. If the predicate is a function, returns true to keep the node, false otherwise.
- [options={}] (Object): The options object.
- [options.caseSensitive=false] (boolean): Case sensitive string comparison. Defaults to false. This option is only available for string comparison.
- [options.exactMatch=false] (boolean): Exact string matching. Defaults to false. This option is only available for string comparison.
- [options.filterPath='name'] (string): Gets the value at path of Node object. Defaults to 'name'. This option is only available for string comparison.
- [options.includeAncestors=true] (boolean): Whether to include ancestor nodes. Defaults to true.
- [options.includeDescendants=true] (boolean): Whether to include descendant nodes. Defaults to true.
const keyword = 'text-to-filter';
const filterOptions = {
caseSensitive: false,
exactMatch: false,
filterPath: 'props.name', // Defaults to 'name'
includeAncestors: true,
includeDescendants: true
};
tree.filter(keyword, filterOptions);
const keyword = 'text-to-filter';
const filterOptions = {
includeAncestors: true,
includeDescendants: true
};
tree.filter(function(node) {
const name = node.name || '';
return name.toLowerCase().indexOf(keyword) >= 0;
});
Flattens all child nodes of a parent node.
- parentNode (Node): The Node object that defines the parent node.
(Array): Returns an array of Node objects containing all the child nodes of the parent node.
Flattens a node.
- node (Node): The Node object.
(Array): Returns a flattened list of Node objects.
Gets a list of child nodes.
- parentNode (Node): The Node object that defines the parent node. If null or undefined, returns a list of top level nodes.
(Array): Returns an array of Node objects containing all the child nodes of the parent node.
Gets a node by its unique id. This assumes that you have given the nodes in the data a unique id.
- id (number|string): An unique node id. A null value will be returned if the id doesn't match.
(Node): Returns a Node object that matches the id, null otherwise.
Returns the node at the specified point. If the specified point is outside the visible bounds or either coordinate is negative, the result is null.
- x (number): A horizontal position within the current viewport.
- y (number): A vertical position within the current viewport.
(Node): Returns a Node object under the given point.
Gets an array of open nodes.
(Array): Returns an array of Node objects containing open nodes.
(Node): Returns the root node, or null if empty.
(number): Returns the index of the selected node, or -1 if not selected.
(Node): Returns the selected node, or null if not selected.
Inserts the specified node after the reference node.
- newNode (Object): The new sibling node.
- referenceNode (Node): The Node object that defines the reference node.
(boolean): Returns true on success, false otherwise.
Inserts the specified node before the reference node.
- newNode (Object): The new sibling node.
- referenceNode (Node): The Node object that defines the reference node.
(boolean): Returns true on success, false otherwise.
Loads data in the tree.
- data (Object|Array): The data is an object or array of objects that defines the node.
Moves a node from its current position to the new position.
- node (Node): The Node object.
- parentNode (Node): The Node object that defines the parent node.
- [index] (number): The 0-based index of where to insert the child node.
(boolean): Returns true on success, false otherwise.
Opens a node to display its children.
- node (Node): The Node object.
- [options={}] (Object): The options object.
- [options.silent=false] (boolean): Sets true to prevent "openNode" event from being triggered.
(boolean): Returns true on success, false otherwise.
Removes all child nodes from a parent node.
- parentNode (Node): The Node object that defines the parent node.
(boolean): Returns true on success, false otherwise.
Removes a node and all of its child nodes.
- node (Node): The Node object.
(boolean): Returns true on success, false otherwise.
Sets the current scroll position to this node.
- node (Node): The Node object.
(boolean): Returns true on success, false otherwise.
- [value] (number): If the value is specified, indicates the new position to set the scroll bar to.
(number): Returns the vertical scroll position.
Selects a node.
- node (Node): The Node object. If null or undefined, deselects the current node.
- [options={}] (Object): The options object.
- [options.autoScroll=true] (boolean): Sets true to automatically scroll to the selected node. Defaults to true.
- [options.silent=false] (boolean): Sets true to prevent "selectNode" event from being triggered. Defaults to false.
(boolean): Returns true on success, false otherwise.
Swaps two nodes.
- node1 (Node): The Node object.
- node2 (Node): The Node object.
(boolean): Returns true on success, false otherwise.
Toggles a node to display or hide its children.
- node (Node): The Node object.
- [options={}] (Object): The options object.
- [options.silent=false] (boolean): Sets true to prevent "closeNode", "openNode", and "selectNode" events from being triggered.
Serializes the current state of a node to a JSON string.
- node (Node): The Node object. If null, returns the whole tree.
(string): Returns a JSON string represented the tree.
Unfilter nodes.
tree.unfilter();
Updates the tree.
Updates the data of a node.
- node (Node): The Node object.
- data (Object): The data object.
- [options={}] (Object): The options object.
- [options.shallowRendering=false] (boolean): Sets true to render only the node without expanded child nodes.