setState

sets state for a tree

void setState(object treeState);

Parameters

treeStateobjectan 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 samples

Details

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
    },
 
    "bsthrillers": {
        "selected": 1
    },
 
    "rc": {
        "selected": 0
    },
 
    "ir": {
        "selected": 1
    },
 
    "history": {
        "selected": 0
    },
 
    "jmf": {
        "selected": 0
    },
 
    "jd": {
        "selected": 0
    }
}
See also
Back to top