Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Madhuri on Aug 26, 2008 17:33
open dhtmlx forum
dhtmlx - Persist tree state

Hi,
I have multiple dhtmlx trees in a page ( one in each tab ).
I want to persist the tree states when the page is reloaded.
I am initializing the tree from HTML List. I am using the following code.
But it is throwing a java script error "Object Expected" at line1 in the unload event. I am not able to trace the cause of error. I guess the trees are getting unloaded before the page unload.
It will be great if someone could help me fix this. Thanks in advance....

            <script>
                dhtmlxEvent(window, "unload", function(){ \\line 1
                        treeboxbox_tree1.saveOpenStates('any1');
treeboxbox_tree2.saveOpenStates('any2');
treeboxbox_tree3.saveOpenStates('any3');});

                dhtmlxEvent(window, "load", function(){
                     window.setTimeout(function(){
                        treeboxbox_tree1.loadOpenStates('any1');
treeboxbox_tree2.loadOpenStates('any2');
treeboxbox_tree3.loadOpenStates('any3'); },100);});
            </script>
Answer posted by Support on Aug 27, 2008 01:56
The problem is that on document unload tree executes destructor code and situation possible , when your custom code will be executed after destructor, which will result in an error. 
To resolve problem you can change the moment when data saved in cookies
  <script> 
  dhtmlxEvent(window, "load", function(){ 
  window.setTimeout(function(){ 
      treeboxbox_tree1.loadOpenStates('any1'); 
      treeboxbox_tree2.loadOpenStates('any2'); 
      treeboxbox_tree3.loadOpenStates('any3');

      treeboxbox_tree1.attachEvent("onOpenEnd",function(){
              treeboxbox_tree1.saveOpenStates('any1');
      });
      treeboxbox_tree2.attachEvent("onOpenEnd",function(){
              treeboxbox_tree2.saveOpenStates('any2');
      });
      treeboxbox_tree3.attachEvent("onOpenEnd",function(){
              treeboxbox_tree3.saveOpenStates('any3');
      });
 },100);}); 
  </script>

Answer posted by Madhuri on Aug 27, 2008 08:34
Thank you very much...That solved the issue...:)