Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Klint on Jun 12, 2008 08:35
open dhtmlx forum
open nodes dynamicaly

Is there any way to open limited number of levels of tree dynamicaly? I mean tree with dynamical loading... Starting from specified node...
Answer posted by scriptag on Jun 12, 2008 08:37

I extended tree object with the following method, which does the job. Try it...

dhtmlXTreeObject.prototype.openLevelsDynamic = function(itemId,depth){
    if(!itemId)
     itemId = this.tmpValueForDynLevelsItemId
    var tmpAr = this.getAllSubItems(itemId).split(",");
    tmpAr[tmpAr.length] = itemId;
    var outAr = new Array(0);
    for(var i=0;i<tmpAr.length;i++){
     if(this.hasChildren(tmpAr[i])===true)
      outAr[outAr.length] = tmpAr[i]
    }
    if(depth){
     this.tmpValueForDynLevels = depth-1;
     this.tmpValueForDynLevelsItemId = itemId||tree.rootId
     this.attachEvent("onOpenDynamicEnd",function(){
      if(this.tmpValueForDynLevels>0)
       this.openLevelsDynamic();
      this.tmpValueForDynLevels = this.tmpValueForDynLevels-1;
     }) 
    }
    if(outAr.length>0)
     this.openItemsDynamic(outAr.join(","));
   }