TreeNode

Properties

19

Class hierarchy

isTreeNode: Boolean= truereadonly
Identifies an object as an instance of TreeNode class, or subclass thereof.
isTreeNode: Boolean= truereadonlystatic
Identifies an object as an instance of TreeNode class, or subclass thereof.

Parent & children

Retrieve all children, excluding filtered out nodes (by traversing sub nodes)

Retrieve all children, including filtered out nodes (by traversing sub nodes)

childLevel: Numberreadonly

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.

convertEmptyParentToLeaf: Boolean | Object= falsestatic

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
}
ParameterTypeDescription
onLoadBoolean

Apply the transformation on load to any parents without children (children : [])

onRemoveBoolean

Apply the transformation when all children have been removed from a parent

Count all children (including sub-children) for a node (in its `firstStore´)

firstChild: Modelreadonly

Get the first child of this node

isLeaf: Booleanreadonly

Is a leaf node in a tree structure?

isLoaded: Booleanreadonly

Returns true for parent nodes with children loaded (there might still be no children)

isParent: Booleanreadonly

Is a parent node in a tree structure?

isRoot: Booleanreadonly

Returns true if this node is the root of the tree

lastChild: Modelreadonly

Get the last child of this node

Get the next sibling of this node

parent: Modelreadonly

This is a read-only property providing access to the parent node.

parentId: Number | String | null

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

This method returns true if this record has all expanded ancestors and is therefore eligible for inclusion in a UI.

ParameterTypeDescription
storeStore

Optional store, defaults to nodes first store

Returns: Boolean

Append a child record(s) to any current children.

ParameterTypeDescription
childRecordModel | Model[] | Object | Object[]

Array of records/data or a single record/data to append

silentBoolean

Pass true to not trigger events during append

Returns: Model | Model[] | null

Bubbles up from this node, calling the specified function with each node.

ParameterTypeDescription
fnfunction

The function to call for each node

skipSelfBoolean

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.

ParameterTypeDescription
fnfunction

The function to call for each node

skipSelfBoolean

True to skip this node in the traversal

Returns: Boolean

Removes all child nodes from this node.

ParameterTypeDescription
silentBoolean

Pass true to not fire Store events during the remove.

Returns: Model[]

Checks if this model contains another model as one of it's descendants

ParameterTypeDescription
childOrIdModel | String | Number

child node or id

skipSelfBoolean

True to ignore self in the traversal

optionsObject | Boolean

A boolean for includeFilteredOutRecords, or an options object

options.includeFilteredOutRecordsBoolean

True to also check filtered out records

Returns: Boolean

Converts a leaf node to a parent node, assigning an empty array as its children

ParameterTypeDescription
silentBoolean

Pass true to not trigger any event

Count visible (expanded)/all children for this node, optionally specifying for which store.

ParameterTypeDescription
onlyVisibleBoolean

Specify true to only count visible (expanded) children.

storeStore

A Store to which this node belongs

Returns: Number

Insert a child record(s) before an existing child record.

ParameterTypeDescription
childRecordModel | Model[] | Object | Object[]

Array of records/data or a single record/data to insert

beforeModel

Optional record to insert before, leave out to append to the end

silentBoolean

Pass true to not trigger events during append

Returns: Model | Model[] | null

Used by stores to assess the record's collapsed/expanded state in that store.

ParameterTypeDescription
storeStore
Returns: Boolean

Remove a child record. Only direct children of this node can be removed, others are ignored.

ParameterTypeDescription
childRecordsModel | Model[]

The record(s) to remove.

isMoveBoolean

Pass true if the record is being moved within the same store.

silentBoolean

Pass true to not trigger events during remove.

Returns: Model[] -

All records (including nested children) removed

Replaces all child nodes with the new node set.

ParameterTypeDescription
childRecordsModel | Model[]

The new child record set.

Returns: Model[]

Traverses all child nodes recursively calling the passed function on a target node before iterating the child nodes.

ParameterTypeDescription
fnfunction

The function to call

skipSelfBoolean

True to ignore self

optionsObject | Boolean

A boolean for includeFilteredOutRecords, or an options object

options.includeFilteredOutRecordsBoolean

True to also include filtered out records

options.useOrderedTreeBoolean

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.

ParameterTypeDescription
fnfunction

The function to call

skipSelfBoolean

True to skip this node in the traversal

optionsObject | Boolean

A boolean for includeFilteredOutRecords, or an options object

options.includeFilteredOutRecordsBoolean

True to also include filtered out records

Traverses child nodes recursively while fn returns true

ParameterTypeDescription
fnfunction
skipSelfBoolean

True to skip this node in the traversal

optionsObject | Boolean

A boolean for includeFilteredOutRecords, or an options object

options.includeFilteredOutRecordsBoolean

True to also include filtered out records

Returns: Boolean

Fields

6

Parent & children

children: Boolean | Object[] | Model[]readonly

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

isFullyLoaded: Boolean

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
}
orderedParentIndex: Numberreadonly

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.

parentId: String | Number | nullreadonly

This is a read-only field provided in server synchronization packets to specify which record id is the parent of the record.

parentIndex: Numberreadonly

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.

remoteChildCount: Numberdeprecated

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.