I have several trees, loaded by XML, that allow users to make choices for querying a database. After they view their results, I want them to be able to return to the query page and see their trees in the same state as they left them (ones that were open, to be open; leaves that were checked, to be checked). Does saveState and loadState do this?
Yes, saveState() and loadState() will do. These methods use “Serialization”, and by default “checked” and open attributes are not serialized. You should use setSerialization method:
tree.setSerializationLevel(true,true);
But note that cookie size is limited. So if you tree isn’t small, it would be better to not save the whole tree in the xml. You may use saveOpenStates/loadOpenStates and use own functionality that saves checked items to cookie and restore them (there is getAllChecked and setCheck methods).
'.$treeName.'_tree.setSerializationLevel(true,true);
'.$treeName.'_tree.loadXML("./includes/'.$treeName.'.xml");
'.$treeName.'_tree.loadState("treeStatex'.$treeName.'");
(Is the “treeStatex” needed here? I noticed that the treeStatex is prefixed to the cookie.)
When I submit the form, I save the state in a saveDomainsStates():
function saveDomainsStates(){
var arDomains = new Array('rx', 'otc', 'bio', 'ani', 'blk');
for (x in arDomains){
var elmTree = window[arDomains[x] + "_tree"];
if (elmTree != null){
elmTree.saveState(arDomains[x] + "_tree");
}
}
}
as you can see from the name of the methods:
saveState - saves the tree to cookie
loadState - load tree from cookie
enableAutoSavingSelected - turns the mode where the selected node will be saved to cookie.
If you have any issues with your tree please provide any kind of sample to reconstruct it.
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan