dynamic loading and loadOpenStates

Hi,

we are using dhtmlxtree (2.5) professional, dynamic loading. All but loadOpenStates works as expected. Here is our code:

   // set up tree
   this.tree = new dhtmlXTreeObject(treeBox,"100%","100%",0);
   this.tree.setImagePath("modules/Categories/views/icons/tree/");		

   this.tree.enableSmartXMLParsing(true);
   this.tree.enableCheckBoxes(0);
   this.tree.enableDragAndDrop(true);
   this.tree.enableItemEditor(true);
   this.tree.setDragBehavior("complex");
   this.tree.preventIECashing(true);
   this.tree.enableThreeStateCheckboxes(false);
   this.tree.setXMLAutoLoading(function(id) {
      this.tree.loadXML('index.php?action=categories_get_tree&parent='+id+((archive) ? "&archive=true" : ""));
   }.bind(this));
		
   this.tree.setXMLAutoLoadingBehaviour("function");	
   this.tree.loadXML(autoLink,function(){
       this.tree.loadOpenStates("updater_tree_open");
   }.bind(this));
      
   this.tree.setEditStartAction(false, false);
		
   // when an item is selected
   this.tree.attachEvent("onSelect",function () {
      this.tree.saveSelectedItem("updater_tree_select");
   $(document).fire("updater:unselect_tree",{tree:this.treeBoxId});
      return true;
   }.bind(this));
		
   // after a tree node is opened		
   this.tree.attachEvent("onOpenEnd",function() {
      this.tree.saveOpenStates("updater_tree_open");
      return true;
   }.bind(this));

The tree is encapsulated in a prototype-class. saveSelectedItem works and loads the right item, as well as saveOpenStates (cookie with right name and content is created). But loadOpenStates has no effect at all.
We are using Firefox 3.6.13 on Mac OSX 10.6 for testing.

Any suggestions?
Thanks
Daniel

Not quite sure , but the next is possible
You have saveOpenStates attached to the onOpen event, so if during data loading any element will be opened - it will trigger saveOpenStates method, which will reset saved state, and when loadOpenStates will be called - original state will be already lost.

Yes I thought of this, too. But if I check the cookie after all loading is done, it contains the expected values. So it seems that it gets not overwritten.
There has to be some piece of code which has effect on loadOpenStates. It worked before I implemented dynamic loading.

Daniel

HI,
I have the same problem, as soon as dynamic loading was implemented, loadOpenStates generates an error in the common dhtmlx javascript file.
I tracked it down to when more than one node is opened, loadOpenStates in a dynamic tree generates a javascript error.
To me, it seems loadOpenStates cannot be used in dynamic tree, which kind of makes sense, since each node must be fetched dynamically. Guess we have to roll our own… :slight_smile:

…ooops, I just found the excellent openItemsDynamic.
Works like magic in dynamic tree, only caveat is that you have to read the state cookie manually.
On my system the cookie is called “treeOpenStatexundefined” :wink:
Loading state now works fine in dynamic tree.
Thanks.