TreeNode
Properties
19
Properties
19Class hierarchy
Parent & children
Retrieve all children, excluding filtered out nodes (by traversing sub nodes)
Retrieve all children, including filtered out nodes (by traversing sub nodes)
Depth in the tree at which this node exists. First visual level of nodes are at level 0, their direct children at level 1 and so on.
This static configuration option allows you to control whether an empty parent task should be converted into a leaf. Enable/disable it for a whole class:
Model.convertEmptyParentToLeaf = false;
By specifying true, all empty parents will be considered leafs. Can also be assigned a configuration object
with the following Boolean properties to customize the behaviour:
Model.convertEmptyParentToLeaf = {
onLoad : false,
onRemove : true
}
| Parameter | Type | Description |
|---|---|---|
onLoad | Boolean | Apply the transformation on load to any parents without children ( |
onRemove | Boolean | Apply the transformation when all children have been removed from a parent |
Count all children (including sub-children) for a node (in its `firstStore´)
Get the first child of this node
Is a leaf node in a tree structure?
Returns true for parent nodes with children loaded (there might still be no children)
Is a parent node in a tree structure?
Returns true if this node is the root of the tree
Get the next sibling of this node
Reading this property returns the id of the parent node, if this record is a child of a node.
Setting this property appends this record to the record with the passed id in the same store that this record is already in.
Note that setting this property is only valid if this record is already part of a tree store.
This is not intended for general use. This is for when a server responds to a record mutation and the server
decides to move a record to a new parent. If a parentId property is passed in the response data for a record,
that record will be moved.
Get the previous sibling of this node
Returns count of all preceding sibling nodes (including their children).
Count visible (expanded) children (including sub-children) for a node (in its firstStore)
Functions
15
Functions
15This method returns true if this record has all expanded ancestors and is therefore
eligible for inclusion in a UI.
| Parameter | Type | Description |
|---|---|---|
store | Store | Optional store, defaults to nodes first store |
Append a child record(s) to any current children.
| Parameter | Type | Description |
|---|---|---|
childRecord | Model | Model[] | Object | Object[] | Array of records/data or a single record/data to append |
silent | Boolean | Pass |
Bubbles up from this node, calling the specified function with each node.
| Parameter | Type | Description |
|---|---|---|
fn | function | The function to call for each node |
skipSelf | Boolean | True to skip this node in the traversal |
Bubbles up from this node, calling the specified function with each node, while the function returns true.
| Parameter | Type | Description |
|---|---|---|
fn | function | The function to call for each node |
skipSelf | Boolean | True to skip this node in the traversal |
Removes all child nodes from this node.
| Parameter | Type | Description |
|---|---|---|
silent | Boolean | Pass |
Checks if this model contains another model as one of it's descendants
| Parameter | Type | Description |
|---|---|---|
childOrId | Model | String | Number | child node or id |
skipSelf | Boolean | True to ignore self in the traversal |
options | Object | Boolean | A boolean for includeFilteredOutRecords, or an options object |
options.includeFilteredOutRecords | Boolean | True to also check filtered out records |
Converts a leaf node to a parent node, assigning an empty array as its children
| Parameter | Type | Description |
|---|---|---|
silent | Boolean | Pass |
Count visible (expanded)/all children for this node, optionally specifying for which store.
| Parameter | Type | Description |
|---|---|---|
onlyVisible | Boolean | Specify |
store | Store | A Store to which this node belongs |
Insert a child record(s) before an existing child record.
| Parameter | Type | Description |
|---|---|---|
childRecord | Model | Model[] | Object | Object[] | Array of records/data or a single record/data to insert |
before | Model | Optional record to insert before, leave out to append to the end |
silent | Boolean | Pass |
Used by stores to assess the record's collapsed/expanded state in that store.
| Parameter | Type | Description |
|---|---|---|
store | Store |
Remove a child record. Only direct children of this node can be removed, others are ignored.
| Parameter | Type | Description |
|---|---|---|
childRecords | Model | Model[] | The record(s) to remove. |
isMove | Boolean | Pass |
silent | Boolean | Pass |
All records (including nested children) removed
Replaces all child nodes with the new node set.
| Parameter | Type | Description |
|---|---|---|
childRecords | Model | Model[] | The new child record set. |
Traverses all child nodes recursively calling the passed function on a target node before iterating the child nodes.
| Parameter | Type | Description |
|---|---|---|
fn | function | The function to call |
skipSelf | Boolean | True to ignore self |
options | Object | Boolean | A boolean for includeFilteredOutRecords, or an options object |
options.includeFilteredOutRecords | Boolean | True to also include filtered out records |
options.useOrderedTree | Boolean | True to traverse unsorted/unfiltered tree |
Traverses all child nodes recursively calling the passed function on child nodes of a target before calling it on the node.
| Parameter | Type | Description |
|---|---|---|
fn | function | The function to call |
skipSelf | Boolean | True to skip this node in the traversal |
options | Object | Boolean | A boolean for includeFilteredOutRecords, or an options object |
options.includeFilteredOutRecords | Boolean | True to also include filtered out records |
Traverses child nodes recursively while fn returns true
| Parameter | Type | Description |
|---|---|---|
fn | function | |
skipSelf | Boolean | True to skip this node in the traversal |
options | Object | Boolean | A boolean for includeFilteredOutRecords, or an options object |
options.includeFilteredOutRecords | Boolean | True to also include filtered out records |
Fields
6
Fields
6Parent & children
Child nodes. To allow loading children on demand, specify children : true in your data. Omit the field for leaf
tasks.
Note, if the tree store loads data from a remote origin, make sure readUrl is specified, and optionally parentIdParamName is set, otherwise loadChildren has to be implemented.
Tree
This field is added to the class at runtime when the Store is configured with
lazyLoad. If set on a parent record at load time, that parent will not cause any
more child load requests. If omitted, it will be automatically set to true when a load request receives fewer
child records than requested.
To specifically set this field for a parent at its children load request, provide it as a property in the data response object:
return {
data : [ ... ],
isFullyLoaded : true
total : 123
}
Or to include grandchildren for a parent, it can be provided as a property on the record data object:
return {
data : [{
id : 1,
name : 'My Parent',
isFullyLoaded : true,
expanded : true,
children : [{
id : 2,
name : 'My Child'
}]
}],
total : 123
}
This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's ordered children array. This index is set on load and gets updated on reordering nodes in tree. Sorting and filtering have no effect on it.
This is a read-only field provided in server synchronization packets to specify which record id is the parent of the record.
This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's children array. This index is set on load and gets updated automatically after row reordering, sorting, etc. To save the order, need to persist the field on the server and when data is fetched to be loaded, need to sort by this field.
This field is added to the class at runtime when the Store is configured with lazyLoad. The number specified should reflect the total amount of children of a parent node, including nested descendants.