Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Stephen on Nov 10, 2009 04:54
open dhtmlx forum
dhtmlxTree serializeTree() checkbox problem

Tree with just a folder if serialised and reloaded then gains a checkbox and folder becomes a file

1) Call doOnLoad() dhtmlxTree loadXML to load into tree one folder without a checkbox
2) Call function to
a) serialise the tree to an XML string
b) (re)load the XML string using loadXMLString
the dhtmlxTree now has a checkbox and the folder becomes a file.

1) function doOnLoad() {
tree = leftLayout.cells("a").attachTree("0");
tree.setImagePath("codebase/imgs/");
tree.enableCheckBoxes(true);
tree.loadXML("xml/tree.xml");
}

2) function mySerialise {
var x = tree.serializeTree();
tree.deleteChildItems(0);
tree.loadXMLString(x);
}

XML
==
<?xml version="1.0" encoding="iso-8859-1"?>
<tree id='0'><item nocheckbox='1' id='apple' text='apple' child='1' im0='folderClosed.gif' im1='folderOpen.gif' im2='folderClosed.gif'><userdata name='folder'>0</userdata></item></tree>
Answer posted by Alex (support) on Nov 10, 2009 05:47

By default tree serializes only id, text and open attributes.

In order to enable serialization of additional parameters you can use setSerializationLevel method:

tree.setSerializationLevel(false,true);

For more details - http://www.dhtmlx.com/dhxdocs/doku.php?id=dhtmlxtree:api_method_dhtmlxtreeobject_setserializationlevel

But nocheckbox attribute isn't serialized even in "full serialization" mode. So, this attribute requires modification in the dhtmlxtree_xw.js:

in this file please, locate the second entrance of the out='<item line and  make the following addition in it:

out='<item 

replace with

out='<item '+(itemNode.nocheckbox?('nocheckbox="1" '):'')+'

Answer posted by Stephen on Nov 10, 2009 08:05
1 amending dhtmlxtree_xw.js works ie checkbox no longer appears but as expected folder still becomes a file
2 so use tree.setSerializationLevel(false, true); and this also works ie folder stays as folder but unexpectedly checkbox now again appears (with dhtmlxtree_xw.js amended)
Answer posted by Alex (support) on Nov 10, 2009 08:10

Have you made a change in the second out='<item occurrence ? The issue looks like you made it in the 1st one.

Answer posted by Stephen on Nov 10, 2009 08:38
You are correct Alex please accept my apology - I was too eager to try it - it works perfectly thank you.