ui.Tree - select option during "OnItemClick" event not working

Hello Team,

I have a datatree. When I click a node, I want that node to be selected and highlighted, which I do through “OnItemClick” event, using the below code.

onItemClick: function(obj,id){
$$(tree).select(id)
}

But then, I have a check included for this event. This check will pass for the first time when the page loads, as it is set to true during initial load. After that, this check will either be true or false, depending upon the other actions we do.

So, the next time when I click a node in the tree, if the check gets passed, then the new clicked node should be shown selected, else it should show the previously selected node as the still selected one (i.e the old node appears as the selected one, not the newly/recently clicked node).

Here is the snippet of my code.

{view:“tree”,
id:“myTree”,
select:true,
adjust:true,
threeState: true,
template:"{common.icon()} {common.folder()} #Name#",
scheme:{
$init:function(obj){
obj.index = this.count();
}
},
on:{
onItemClick:function(id, e, trg) {
if(checkedit== true) {
let obj = $$(myTree).getItem(id);
GlobalID = obj.NavID;
$$(myTree).select(id);
} else {
me.ui.$$(‘myTree’).data.each(function(obj) {
if(obj.NavID== GlobalID) {
oldselect = obj.id;} })
webix.alert('Setting to the Old Node");
$$(myTree).select(oldselect);
console.log(oldselect);
}
},
},
}

But the issue I face is, even though my if and else works properly and even though the ids are shown correctly (that is old id gets printed in the console of the else part in the code), the UI shows the newly clicked node as the “Selected” one always after a click is done.

Please help. Thank you.

try to use select:false in tree config.
in this case items will not be selected by default.

Fantastic.
Thank you so much @intregal. I had put select:true in the config. Changing that to false fixed the issue. Thank you once again :slight_smile: