Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Prasad PG on Aug 22, 2008 10:36
open dhtmlx forum
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?

Answer posted by Support on Aug 25, 2008 02:48

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. 

Answer posted by Prasad PG on Aug 26, 2008 00:25

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!

Answer posted by Support on Aug 26, 2008 06:37
>>the 0 given below should actually be 1.
yes, you are correct, was a typo from my side