Skip to main content

setState()

sets state for a tree

setState(state: ITreeState): void;

Parameters:

state: object - an object of key:value pairs, where key is the id of a tree item and value is its state

Example

// getting the state of a tree
var treeState = tree.getState();

// restoring the state of a tree
tree.setState(treeState);

Related sample: Tree. Setting Tree state

The treeState object contains key:value pairs, where key is the id of a tree item and value is its state. The state object of a tree item includes two properties:

selected(number) the status of a checkbox of an item:
  • 0 - unselected
  • 1 - selected
  • 2 - indeterminate (for the parent item, in case its children are partially checked)
open(boolean) checks whether a tree item is open (for folders with items)

Here is an example of a treeState object:

{
"books": {
"open": true,
"selected": 2
},

"mystery": {
"open": true,
"selected": 2
},

"thrillers": {
"selected": 1
},

"rc": {
"selected": 0
},

"ir": {
"selected": 1
},

"history": {
"selected": 0
},

"jmf": {
"selected": 0
},

"jd": {
"selected": 0
}
}