DHTMLX tree with multiselection


I’m using a DHTMLX tree with multiselection;
The requirement is that all the selected nodes should be checked when they are selected or multiselected.
Is there any API function or any solution for this?



The answer to this has been posted:
If you want to check all selected items, it can be done as



var ids = tree.getSelectedItemId().split(",");
for (var i=0; i < ids.length; i++)
     tree.setCheck(ids[i],1);








Now, I want to know how to uncheck the deselected and multi-deselected nodes. Is there any API function available for this?


There is no any built-in event to monitor unselecting of nodes, but you can try to use onClick event in next way


tree.attachEvent(“onClick”,function(){
var ids = tree.getAllChecked().split(",");
for (var i=0; i < ids.length; i++)
tree.setCheck(ids[i],0);

var ids = tree.getSelectedItemId().split(",");
for (var i=0; i < ids.length; i++)
tree.setCheck(ids[i],0);
})

In such case, each time when row selected, grid will clear all existing checkboxes and check again only selected rows.



Thanks a lot;



a small correction in the answer: the 0 given below should actually be 1.



tree.attachEvent(“onClick”,function(){
       var ids = tree.getAllChecked().split(",");
       for (var i=0; i < ids.length; i++)
            tree.setCheck(ids[i],0);

       var ids = tree.getSelectedItemId().split(",");
       for (var i=0; i < ids.length; i++)
            tree.setCheck(ids[i],0);
})



Once again many many Thanks!

the 0 given below should actually be 1.
yes, you are correct, was a typo from my side