How to restore dhtmlxTree opened nodes when user comes back

You can store state of nodes in cookies … okies.html

to save open state


load open state


I am unable to get this to work.

I have a multi-tier treegrid, with alphanumeric rowIds (e.g., “1|O” or “2|C|3”)

Here’s what I do:

  1. When grid is constructed I define an onOpenEnd event.
  2. In the onOpenEnd event I call saveOpenState (using a pre-defined cookie)
  3. When grid is loaded (via XML, so I do this in the onXLE event) I call loadOpenState (using the same pre-defined cookie).

There are no “open=‘1’” attributes in the XML.

check if you call loadOpenState method only after all rows are loaded:


The loadOpenState is done in the onXLE event which is described in your documentation to occur “simultaneously with ending XML parsing, new items are already available in the grid”. And, I can confirm that the items are already available, since I have other code in this event that functions properly that involves interactions with the grid rows.

This code works as expected at the local example:

mygrid = new dhtmlXGridObject('gridbox'); ... mygrid.attachEvent("onOpenEnd",function(){ mygrid.saveOpenStates(); }) mygrid.loadXML("test_list_1.xml",function(){ mygrid.loadOpenStates(); });
dhtmlxgrid_ssc.js file must be attached on the page

I’m not working with a grid , but a treegrid.

It will work for treeGrid also.

I’ve been unable to track with your suggested approach. You stated that dhtmlxgrid_ssc.js is necessary, which I have included (see below). But when I try to attach the onOpenEnd event I get “Object does not support this property or method.”

In addition to the common js file, here are the JS files included:

<script type='text/JavaScript' src='DHTMLX/dhtmlxGrid/codebase/dhtmlxgrid.js'></script>
<script type='text/JavaScript' src='DHTMLX/dhtmlxGrid/codebase/dhtmlxgridcell.js'></script>
<script type='text/JavaScript' src='DHTMLX/dhtmlxGrid/codebase/ext/dhtmlxgrid_mcol.js'></script>
<script type='text/JavaScript' src='DHTMLX/dhtmlxGrid/codebase/ext/dhtmlxgrid_ssc.js'></script>
<script type='text/JavaScript' src='DHTMLX/dhtmlxGrid/codebase/ext/dhtmlxgrid_post.js'></script>
<script type='text/JavaScript' src='DHTMLX/dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_sub_row.js'></script>

get “Object does not support this property or method.”
This issue may occurs only if one of the necessary files is not included. Check at which row does this error points and check what file method is required … _toc_alpha

Might there be a conflict between what DHTMLX saves when saving the open state, and my unique row ids? Both would appear to be using the vertical bar / pipe character. See cookie sample below:

One of my rows has id = 1|C-0|O-1|C and the second one has id = 4|C-0|O-4|C, so whatever the saveOpenState is doing prepends the 0|0| and appends the |1|0.

“Object does not support this property or method.”
such issue may occur only if script cannot file one of the functions which you are trying to use. It is not related rows ids.

It seems that me former my posts on this topic are are not being fully read.

I do not use the loadXML method, but the post(url) method. XML is returned, however. I am using the onXLE event and, as mentioned before, have put the loadOpenStates(cookie) therein. However, the open states are not being restored. Does the loadOpenStates need to be in yet a different event handler and, if so, which one?

I can confirm that the saveOpenStates(cookie) is indeed working within the onOpenEnd event handler since, as I showed in my previous post, the cookie is being updated.