Methods
(static) isTreeNode(obj) → {boolean}
Check if an object is a TreeNode.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | Object |
Returns:
If object is a TreeNode.
- Type
- boolean
(static) isTreeNodes(obj) → {boolean}
Check if an object is a TreeNodes array.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | Object |
Returns:
If object is a TreeNodes array.
- Type
- boolean
addNode(node) → {TreeNode}
Adds a new node. If a sort method is configured,
the node will be added in the appropriate order.
Parameters:
Name | Type | Description |
---|---|---|
node |
object | Node |
Returns:
Node object.
- Type
- TreeNode
addNodes(nodes) → {TreeNodes}
Add nodes.
Parameters:
Name | Type | Description |
---|---|---|
nodes |
array | Array of node objects. |
Returns:
Added node objects.
- Type
- TreeNodes
available(full) → {TreeNodes}
Query for all available nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
blur() → {TreeNodes}
Blur children in this collection.
Returns:
Array of node objects.
- Type
- TreeNodes
blurDeep() → {TreeNodes}
Blur (deeply) all nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
boundingNodes() → {array}
Compares any number of TreeNode objects and returns
the minimum and maximum (starting/ending) nodes.
Returns:
Array with two TreeNode objects.
- Type
- array
canAutoDeselect() → {boolean}
Check if the tree will auto-deselect currently selected nodes
when a new selection is made.
Returns:
If tree will auto-deselect nodes.
- Type
- boolean
checked(full) → {TreeNodes}
Query for all checked nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
clean() → {TreeNodes}
Clean nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
clearSearch() → {Tree}
Clear nodes matched by previous search, restore all nodes and collapse parents.
Returns:
Tree instance.
- Type
- Tree
clone() → {TreeNodes}
Clones (deeply) the array of nodes.
Note: Cloning will *not* clone the context pointer.
Returns:
Array of cloned nodes.
- Type
- TreeNodes
collapse() → {TreeNodes}
Collapse nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
collapsed(full) → {TreeNodes}
Query for all collapsed nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
collapseDeep() → {TreeNodes}
Collapse (deeply) all children.
Returns:
Array of node objects.
- Type
- TreeNodes
concat(nodes) → {TreeNodes}
Concat multiple TreeNodes arrays.
Parameters:
Name | Type | Description |
---|---|---|
nodes |
TreeNodes | Array of nodes. |
Returns:
Resulting node array.
- Type
- TreeNodes
copy(dest, hierarchy, includeState) → {object}
Copy nodes to another tree instance.
Parameters:
Name | Type | Description |
---|---|---|
dest |
object | Destination Inspire Tree. |
hierarchy |
boolean | Include necessary ancestors to match hierarchy. |
includeState |
boolean | Include itree.state object. |
Returns:
Methods to perform action on copied nodes.
- Type
- object
createNode(obj) → {TreeNode}
Creates a TreeNode without adding it. If the obj is already a TreeNode it's returned without modification.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | Source node object. |
Returns:
Node object.
- Type
- TreeNode
deepest() → {TreeNodes}
Return deepest nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
deselect() → {TreeNodes}
Deselect nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
deselectDeep() → {TreeNodes}
Deselect (deeply) all nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
disableDeselection() → {Tree}
Disable auto-deselection of currently selected nodes.
Returns:
Tree instance.
- Type
- Tree
each(iteratee) → {TreeNodes}
Iterate each TreeNode.
Parameters:
Name | Type | Description |
---|---|---|
iteratee |
function | Iteratee invoke for each node. |
Returns:
Array of node objects.
- Type
- TreeNodes
editable(full) → {TreeNodes}
Query for all editable nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
editing(full) → {TreeNodes}
Query for all nodes in editing mode.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
enableDeselection() → {Tree}
Enable auto-deselection of currently selected nodes.
Returns:
Tree instance.
- Type
- Tree
every(tester) → {boolean}
Check if every node passes the given test.
Parameters:
Name | Type | Description |
---|---|---|
tester |
function | Test each node in this collection, |
Returns:
True if every node passes the test.
- Type
- boolean
expand() → {TreeNodes}
Expand children.
Returns:
Array of node objects.
- Type
- TreeNodes
expandDeep() → {Promise.<TreeNodes>}
Expand (deeply) all nodes.
Returns:
Promise resolved when all children have loaded and expanded.
- Type
- Promise.<TreeNodes>
expanded() → {TreeNodes}
Query for all expanded nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
extract(predicate) → {TreeNodes}
Clone a hierarchy of all nodes matching a predicate.
Because it filters deeply, we must clone all nodes so that we
don't affect the actual node array.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
string | function | State flag or custom function. |
Returns:
Array of node objects.
- Type
- TreeNodes
filter(predicate) → {TreeNodes}
Filter all nodes matching the given predicate.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | Test function. |
Returns:
Array of node objects.
- Type
- TreeNodes
filterBy(predicate) → {TreeNodes}
Filter all nodes matching the given predicate.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
string | function | State flag or custom function. |
Returns:
Array of node objects.
- Type
- TreeNodes
find(predicate) → {TreeNode}
Returns the first node matching predicate.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | Predicate function, accepts a single node and returns a boolean. |
Returns:
First matching TreeNode, or undefined.
- Type
- TreeNode
first(predicate) → {TreeNode}
Returns the first shallow node matching predicate.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | Predicate function, accepts a single node and returns a boolean. |
Returns:
First matching TreeNode, or undefined.
- Type
- TreeNode
flatten(predicate) → {TreeNodes}
Flatten and get only node(s) matching the expected state or predicate function.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
string | function | State property or custom function. |
Returns:
Flat array of matching nodes.
- Type
- TreeNodes
focused(full) → {TreeNodes}
Query for all focused nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
forEach(iteratee) → {TreeNodes}
Iterate each TreeNode.
Parameters:
Name | Type | Description |
---|---|---|
iteratee |
function | Iteratee invoke for each node. |
Returns:
Array of node objects.
- Type
- TreeNodes
get(index) → {TreeNode}
Get a specific node by its index, or undefined if it doesn't exist.
Parameters:
Name | Type | Description |
---|---|---|
index |
int | Numeric index of requested node. |
Returns:
Node object. Undefined if invalid index.
- Type
- TreeNode
hidden(full) → {TreeNodes}
Query for all hidden nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
hide() → {TreeNodes}
Hide nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
hideDeep() → {TreeNodes}
Hide (deeply) all nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
indeterminate(full) → {TreeNodes}
Query for all indeterminate nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
indexOf(node) → {int}
Get the index of the given node.
Parameters:
Name | Type | Description |
---|---|---|
node |
TreeNode | Root tree node. |
Returns:
Index of the node.
- Type
- int
insertAt(index, object) → {TreeNode}
Insert a new node at the given position.
Parameters:
Name | Type | Description |
---|---|---|
index |
integer | Index at which to insert the node. |
object |
object | Raw node object or TreeNode. |
Returns:
Node object.
- Type
- TreeNode
invoke(methods) → {TreeNodes}
Invoke method(s) on each node.
Parameters:
Name | Type | Description |
---|---|---|
methods |
string | array | Method name(s). |
Returns:
Array of node objects.
- Type
- TreeNodes
invokeDeep(methods) → {TreeNodes}
Invoke method(s) deeply.
Parameters:
Name | Type | Description |
---|---|---|
methods |
string | array | Method name(s). |
Returns:
Array of node objects.
- Type
- TreeNodes
isEventMuted(eventName) → {boolean}
Check if an event is currently muted.
Parameters:
Name | Type | Description |
---|---|---|
eventName |
string | Event name. |
Returns:
If event is muted.
- Type
- boolean
isTree(object) → {boolean}
Check if an object is a Tree.
Parameters:
Name | Type | Description |
---|---|---|
object |
object | Object |
Returns:
If object is a Tree.
- Type
- boolean
join(separator) → {string}
Join nodes into a resulting string.
Parameters:
Name | Type | Description |
---|---|---|
separator |
string | Separator, defaults to a comma |
Returns:
Strings from root node objects.
- Type
- string
last(predicate) → {TreeNode}
Returns the last shallow node matching predicate.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | Predicate function, accepts a single node and returns a boolean. |
Returns:
Last matching shallow TreeNode, or undefined.
- Type
- TreeNode
lastSelectedNode() → {TreeNode}
Get the most recently selected node, if any.
Returns:
Last selected node, or undefined.
- Type
- TreeNode
load(loader) → {Promise.<TreeNodes>}
Load data. Accepts an array, function, or promise.
Parameters:
Name | Type | Description |
---|---|---|
loader |
array | function | Promise | Array of nodes, function, or promise resolving an array of nodes. |
Returns:
Promise resolved upon successful load, rejected on error.
- Type
- Promise.<TreeNodes>
Example
tree.load($.getJSON('nodes.json'));
loading(full) → {TreeNodes}
Query for all nodes currently loading children.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
loadMore(event) → {Promise.<TreeNodes>}
Load additional nodes for the root context.
Parameters:
Name | Type | Description |
---|---|---|
event |
Event | Click or scroll event if DOM interaction triggered this call. |
Returns:
Resolves with request results.
- Type
- Promise.<TreeNodes>
map(iteratee) → {TreeNodes}
Create a new collection after passing every node through iteratee.
Parameters:
Name | Type | Description |
---|---|---|
iteratee |
function | Node iteratee. |
Returns:
New array of node objects.
- Type
- TreeNodes
matched(full) → {TreeNodes}
Query for all nodes matched in the last search.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
move(index, newIndex, target) → {TreeNode}
Move node at a given index to a new index.
Parameters:
Name | Type | Description |
---|---|---|
index |
int | Current index. |
newIndex |
int | New index. |
target |
TreeNodes | Target TreeNodes array. Defaults to this. |
Returns:
Node object.
- Type
- TreeNode
mute(events) → {Tree}
Pause events.
Parameters:
Name | Type | Description |
---|---|---|
events |
array | Event names to mute. |
Returns:
Tree instance.
- Type
- Tree
muted() → {boolean|array}
Get current mute settings.
Returns:
Muted events. If all, true.
- Type
- boolean | array
node(id) → {TreeNode}
Get a node.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | number | ID of node. |
Returns:
Node object.
- Type
- TreeNode
nodes(refs) → {TreeNodes}
Get all nodes in a tree, or nodes for an array of IDs.
Parameters:
Name | Type | Description |
---|---|---|
refs |
array | Array of ID references. |
Returns:
Array of node objects.
- Type
- TreeNodes
Example
const all = tree.nodes()
const some = tree.nodes([1, 2, 3])
pagination() → {object}
Get the root TreeNodes pagination.
Returns:
Pagination configuration object.
- Type
- object
pop() → {TreeNode}
Pop node in the final index position.
Returns:
Node object.
- Type
- TreeNode
push(node) → {int}
Add a TreeNode to the end of the root collection.
Parameters:
Name | Type | Description |
---|---|---|
node |
TreeNode | Node object. |
Returns:
The new length
- Type
- int
reduce(iteratee) → {any}
Reduce nodes.
Parameters:
Name | Type | Description |
---|---|---|
iteratee |
function | Iteratee function |
Returns:
Resulting data.
- Type
- any
reduceRight(iteratee) → {any}
Right-reduce root nodes.
Parameters:
Name | Type | Description |
---|---|---|
iteratee |
function | Iteratee function |
Returns:
Resulting data.
- Type
- any
reload() → {Promise.<TreeNodes>}
Reload/re-execute the original data loader.
Returns:
Load method promise.
- Type
- Promise.<TreeNodes>
remove(node) → {TreeNodes}
Remove a node.
Parameters:
Name | Type | Description |
---|---|---|
node |
TreeNode | Node object. |
Returns:
Array of node objects.
- Type
- TreeNodes
removeAll() → {Tree}
Remove all nodes.
Returns:
Tree instance.
- Type
- Tree
removed(full) → {TreeNodes}
Query for all soft-removed nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
restore() → {TreeNodes}
Restore nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
restoreDeep() → {TreeNodes}
Restore (deeply) all nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
reverse() → {TreeNodes}
Reverse node order.
Returns:
Reversed array of node objects.
- Type
- TreeNodes
search(query) → {Promise.<TreeNodes>}
Search nodes, showing only those that match and the necessary hierarchy.
Parameters:
Name | Type | Description |
---|---|---|
query |
* | Search string, RegExp, or function. |
Returns:
Promise resolved with an array of matching node objects.
- Type
- Promise.<TreeNodes>
select() → {TreeNodes}
Select nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
selectable(full) → {TreeNodes}
Query for all selectable nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
selectBetween(startNode, endNode) → {Tree}
Select all nodes between a start and end node.
Starting node must have a higher index path so we can work down to endNode.
Parameters:
Name | Type | Description |
---|---|---|
startNode |
TreeNode | Starting node |
endNode |
TreeNode | Ending node |
Returns:
Tree instance.
- Type
- Tree
selectDeep() → {TreeNodes}
Select (deeply) all nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
selected(full) → {TreeNodes}
Query for all selected nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes
selectFirstAvailableNode() → {TreeNode}
Select the first available node.
Returns:
Selected node object.
- Type
- TreeNode
shift() → {TreeNode}
Shift node in the first index position.
Returns:
Node object.
- Type
- TreeNode
show() → {TreeNodes}
Show nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
showDeep() → {TreeNodes}
Show (deeply) all nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
slice(begin, end) → {Array}
Get a shallow copy of a portion of nodes.
Parameters:
Name | Type | Description |
---|---|---|
begin |
int | Starting index. |
end |
int | End index. |
Returns:
Array of selected subset.
- Type
- Array
softRemove() → {TreeNodes}
Soft-remove nodes.
Returns:
Array of node objects.
- Type
- TreeNodes
some(tester) → {boolean}
Check if at least one node passes the given test.
Parameters:
Name | Type | Description |
---|---|---|
tester |
function | Test each node in this collection, |
Returns:
True if at least one node passes the test.
- Type
- boolean
sort(compareFn) → {TreeNodes}
Sort nodes using a function.
Parameters:
Name | Type | Description |
---|---|---|
compareFn |
function | Comparison function. |
Returns:
Root array of node objects.
- Type
- TreeNodes
sortBy(sorter) → {TreeNodes}
Sort nodes using a function or key name.
If no custom sorter given, the configured "sort" value will be used.
Parameters:
Name | Type | Description |
---|---|---|
sorter |
string | function | Sort function or property name. |
Returns:
Array of node obejcts.
- Type
- TreeNodes
sortDeep(compareFn) → {TreeNodes}
Deeply sort nodes.
Parameters:
Name | Type | Description |
---|---|---|
compareFn |
function | Comparison function. |
Returns:
Root array of node objects.
- Type
- TreeNodes
splice(start, deleteCount, node) → {Array}
Remove and/or add new TreeNodes into the root collection.
Parameters:
Name | Type | Description |
---|---|---|
start |
int | Starting index. |
deleteCount |
int | Count of nodes to delete. |
node |
TreeNode | Node(s) to insert. |
Returns:
Array of selected subset.
- Type
- Array
state(name, newVal) → {TreeNodes}
Set nodes' state values.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Property name. |
newVal |
boolean | New value, if setting. |
Returns:
Array of node objects.
- Type
- TreeNodes
stateDeep(name, newVal) → {TreeNodes}
Set (deeply) nodes' state values.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Property name. |
newVal |
boolean | New value, if setting. |
Returns:
Array of node objects.
- Type
- TreeNodes
swap(node1, node2) → {TreeNodes}
Swap two node positions.
Parameters:
Name | Type | Description |
---|---|---|
node1 |
TreeNode | Node 1. |
node2 |
TreeNode | Node 2. |
Returns:
Array of node objects.
- Type
- TreeNodes
toArray() → {array}
Get a native node Array.
Returns:
Array of node objects.
- Type
- array
toString() → {string}
Get a string representation of node objects.
Returns:
Strings from root node objects.
- Type
- string
unmute(events) → {Tree}
Resume events.
Parameters:
Name | Type | Description |
---|---|---|
events |
array | Events to unmute. |
Returns:
Tree instance.
- Type
- Tree
unshift() → {number}
Add a TreeNode in the first index position.
Returns:
The new length
- Type
- number
visible(full) → {TreeNodes}
Query for all visible nodes.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | Retain full hiearchy. |
Returns:
Array of node objects.
- Type
- TreeNodes