Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by TonyW on Apr 08, 2008 21:52
open dhtmlx forum
dhtmlxtree - large tree with many branches

On opening a branch is it possible to close any opened branch of the same level and/or parent. Screen limitations would be enhanced if the previously opened branch could be collapsed.
Any solution
Thanks
TonyW
Your support service is great!!
Answer posted by Support on Apr 09, 2008 05:54
It is possible. You can try to do it using onOpenStart event handler. This function called when item is opened/closed. There you can close the last opened item if it not a parent of the item which you are opening.
In order to get a parent item id of a particular item,  the getParentId method can be used.


Here is the example how it can be done: 
 
var lastopened = "";

tree.attachEvent("onOpenStart",function(id,state){
    
   if(state != 1){ /*if the current state is not "opened" (you don't try close to  node) */
    
       if(lastopened != ""){
         if(!isparent(id,lastopened))   tree.closeItem(lastopened);
       }
       lastopened = id;
   }
   return true
 
})
 
function isparent(id,parent){

   if(id!="0"){

    if(tree.getParentId(id)!= parent){
         isparent(tree.getParentId(id),parent)
    }
    else return true
   }
   return false   
}

Please, see tree API and details about this event  in the documentation docs/alpha.html and on our site http://www.dhtmlx.com/docs/products/dhtmlxTree/doc/events.html.