performance: dynamic tree loading and refreshing current lev

[ Topic already exists -  interactive mode on existing topic not showing 'Answer' , see:
Stephen
, posted: Nov 05, 2009 07:36 | Direct link: [dhtmlx.com/docs/products/kb/inde ... 92&a=20605](http://dhtmlx.com/docs/products/kb/index.php?s=normal&q=12692&a=20605) ]

Alex, the tree refresh code you supplied works gereat ie
--
  tree.saveOpenStates(); // save tree open nodes
  tree.deleteChildItems(0); // delete tree
  tree.loadXML // load tree first level
  tree.loadOpenStates(); // reopen nodes
--
its good but it is it possible to make it even better? i.e. if you have alot of tree nodes open then refresh the tree using the abpve code you then see
1. tree with many open nodes dissappears
2. tree reappears but wit all nodes closed
3. tree nodes start to ripple open
Is there a way of avoiding this? I was wondering if maybe for example a temporary hidden tree could be loaded with the refreshed tree and once loaded swapped with the visisble tree so that the refreshed tree appears fully open?



Hello,


you can try to use the following approach:


/hides tree/
tree.allTree.style.visibility = “hidden”;

tree.saveOpenStates(); // save tree open nodes
tree.deleteChildItems(0); // delete tree
tree.loadXML // load tree first level

/shows tree when items are opened (loaded)/
tree.attachEvent(“onAllOpenDynamic”,function(){
tree.allTree.style.visibility = “visible”
})
tree.loadOpenStates(); // reopen nodes



Hi Alex, thanks the code worked, with a tweak - as below - but I think
I prefer to see the tree refreshed and the nodes rippling back open
rather than have no tree visibile for many seconds.


Is it not possible to either
1) Freeze the tree on display until its refreshed?
2) Or else use two trees i.e. instead of making the tree
invisible, keep showing it while a second tree is refreshed and once
refreshed switch to displaying the refreshed tree? Something like below- which does not work…


  var mytree = new dhtmlXTreeObject(“mytreeHidden”,“0%”,“0%”,0);
  mytree.setXMLAutoLoading();
  mytree.attachEvent(“onXLE”,function(){
  tree=mytree;
  });
  mytree.loadXML(“xml/diratreeall.php”);

–tweaked last post code
  if (!tree.getXMLState()) {
    tree.saveOpenStates();
    tree.deleteChildItems(0);
    tree.allTree.style.visibility = “hidden”;
    tree.loadXML(",function(){
      tree.loadOpenStates();
    });
    tree.attachEvent(“onAllOpenDynamic”,function(){
      tree.allTree.style.visibility = “visible”;
    });
  }



You can try to use two trees as you described. For example (but the following method wasn’t tested locally):











tree.saveOpenStates();

showTempTree(1);

tree.deleteChildItems(0);

tree.loadXML(",function(){
tree.loadOpenStates();
});

tree.attachEvent(“onAllOpenDynamic”,function(){
showTempTree(0);
});

function showTempTree(mode){
if(mode){
var xml = tree.serializeTree()
tree1.deleteChildItems(0);
tree1.loadXMLString(xml);
document.getElementById(“treeboxbox_tree1”).style.display="";
}
else document.getElementById(“treeboxbox_tree1”).style.display=“none”;
}




Trying to see how I can use this but problem is I’m not using

I’m using
tree = leftLayout.cells(“a”).attachTree(“0”);


Hello,


unfortunatey tree doesn’t provide ready solutions to do that. The customization can be done only for additional fee. If you are interested in it, please contact us at sales@dhtmlx.com

Alex I’ve a solution.

I create a tmp tree just for loading XML+saved states which I put into a string for loading into my tree.

atree = leftLayout.cells(“a”).attachTree(“0”); // my tree
tmpTree = layout.cells(“b”).attachTree(“0”); // just for loading

// save my tree states
atree.saveOpenStates(); // save tree open nodes

// load tmp tree + saved states and serialise
tmpTree.deleteChildItems(0); // delete tree
tmpTree.loadXML // load tree first level
tmpTree.loadOpenStates(); // reopen nodes
var xmlString = tmpTree.serializeTree();


// load my tree ie load tmpTree serialised string
atree.deleteChildItems(0);

tree.loadXMLString(xmlString );


But I’ve noticed that performance is severly hit the more open nodes that need to be saved/loaded (cookie). Whereas loadXMLString is pretty fast. Any suggestions on improving performance?


Unfortunately tree doesn’t provide any other solution.


loadOpenState method restores all open states (this is your requirement) and rendering can take time if open structure is rather big.

Regarding loadOpenState restores all open states and rendering can take time if open structure is rather
big.

It appears saveOpenStates is for the whole tree or is it possible to only save from a selected node and the tree below?

Both methods can be used only for the whole tree.
If the selected branch doesn’t contain a lot of nodes, you can try to use smartRefreshBranch for it.