Work with Selection object
The selection object API lets you manage Tree items: select an item, remove selection, and get the id or the object of a selected Tree item.
Enabling/Disabling Selection object
From v7.0, you can enable item selection with the enable() method of the selection object:
tree.selection.enable();
To disable item selection in Tree, use the disable() method of the selection object:
tree.selection.disable();
Related sample: Tree. Disable / enable selection
For finer control over item selection, apply the Selection object events.
Selecting an item
To select a Tree item, use the add() method of the selection object. The method takes an item id as a parameter:
const id = tree.selection.getId(); // -> "2"
tree.selection.add("2");
Unselecting an item
To remove selection from a selected item, apply the remove() method of the selection object. The method can take an item id as a parameter:
tree.selection.remove("2");
From v7.0, the method unselects all previously selected items when you call it without parameters:
tree.selection.remove();
Getting id of a selected item
You can get the id of the currently selected item with the getId() method of the selection object:
const selected = tree.selection.getId(); // -> "2"
Getting object of a selected item
You can also get the object of a selected item with the getItem() method of the selection object:
const item = tree.selection.getItem();