By default, single selection mode is used. You can select/unselect tree items by using the following methods:
// select item
myTreeView.selectItem(id);
// unselect item
myTreeView.unselectItem(id);
// get selected id
myTreeView.getSelectedId(); // returns the selected item's id
You can enable multiple selection mode as follows:
// during initialization
var myTreeView = new dhtmlXTreeView({
multiselect: true
});
// or after initialization
myTreeView.enableMultiselect(true);
To select several items, hold down the CTRL key and select as usual.
In case multiple selection mode is used to select several items, you need to pass an array with ids as a parameter for selection methods:
// select several items
myTreeView.selectItem([id1, id2, ..., idN]);
// unselect several items
myTreeView.unselectItem([id2, id3, ..., idM]);
// get selected ids
var ids = myTreeView.getSelectedId(); // returns an array with ids
Related sample: Multiple selection
Back to top