Skip to main content

setState()

sets state for a tree

setState(state: { [id: string]: { selected: number, open: boolean }}): void;

Parameters:

  • state: object - an object of key:value pairs, where key is the id of a tree item and value is an object which 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)

Example

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

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

Related sample: Tree. Setting Tree state

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