Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Steve on Jan 21, 2008 08:22
open dhtmlx forum
Tree openItemsDynamic

I have a problem restoring opened branches on a dynamic tree.
I get a javascript error (XMLload is null) in IE if parts of the hierarchy have been removed since the last time the tree was saved if I simply use the openItemsDynamic with a list from a cookie.

function restoreTreeState_old() {
var asIds=GetCookie("treestate") + "";
if (asIds!="undefined") mobjTree.openItemsDynamic(asIds, false);
}


I changed the code to this, but now it doesn't fully open all the branches

var miExpandedNode=0;
var masExpandIds=false;
function restoreTreeState() {
var sIds=GetCookie("treestate") + "";
var asIds=sIds.split(",");
if (!masExpandIds && sIds!="undefined") masExpandIds=asIds;
if (miExpandedNode<masExpandIds.length) {
mobjTree.attachEvent("onOpenDynamicEnd",restoreTreeState);
if (mobjTree.getItemText(masExpandIds[miExpandedNode]))
mobjTree.openItemsDynamic(masExpandIds[miExpandedNode++], false);
else
miExpandedNode++;
}
else
mobjTree.attachEvent("onOpenDynamicEnd",onNodesLoaded);
}

Any ideas how to make this work?

Thanks
Answer posted by Support on Jan 22, 2008 06:11
Actually tree contains native functionality for operating with saved states
    tree.saveOpenStates(...
    tree.loadOpenStates(...


>>I get a javascript error (XMLload is null) in IE if parts of the hierarchy have been removed since the last time the tree was saved
In case of your code, problem can be resolved by next code modification

dhtmlXTreeObject.prototype._stepOpen=function(that){
             if(!that.ClosedElem.length || !that._globalIdStorageFind(that.ClosedElem[that.ClosedElem.length-1])){
                 that.onXLE = that.onLoadReserve;
                 if (that._opnItmsDnmcFlg)
                     that.selectItem(that.G_node,true);
                 if ((that.onXLE)&&(arguments[1])) that.onXLE.apply(that,arguments);
                 that.callEvent("onOpenDynamicEnd",[]);
                 return;
             }
             that.G_node=that.ClosedElem.pop();