<h2><ahref="http://www.scbr.com/docs/products/dhtmlxTree/index.shtml"target="_top"title="Visit javascript tree home page">dhtmlXTree</a> Guide and Samples</h2>
In most cases functions specified inside event handlers get some values with the arguments. For details about passed arguments please refer to <ahref="alpha.html">API documentation</a>.<br>
<strong><tree></strong> node is mandatory. It specifies the parent of loading block of data. According to this its id parameter specifies the ID oth that parent.
To load root level you need to specify the ID you used when created tree object: new myObjTree(boxObject,width,height,<b>0</b>) <br>
<strong><item></strong> can contain subitems (in order to load more than one level at once) or not.<br>
If your tree should contain large amount of nodes (or you simply do not want to waist time loading hidden nodes), it would be better to load them on demand, not at once.
For this purpose we made the tree to load levels dynamically using XML. <br>
Serialization methods allows getting tree in xml representation (xml string). Various levels of serializations define the number of tree parameters reflected in resulting XML:<br>
To move Item programaticaly developer can use the following ways: <br>
<br>
<strong>To move upp/down/left:</strong>
<XMP>
tree.moveItem(nodeId,mode)
</XMP>
<i>mode</i> possible values are:<br>
<li>"down" - move node down in list of nodes (do not pay attention on hierarchy)</li>
<li>"up" - move node up in list of nodes</li>
<li>"left" - move node up in hierarchy</li>
<br><br>
<strong>To move directly into position (within tree)</strong>
<XMP>
tree.moveItem(nodeId,mode,targetId)
</XMP>
<i>mode</i> possible values are:<br>
<li>"item_child" - place node as child of node specified in third argument</li>
<li>"item_sibling" - place node as sibling of node specified in third argument</li><br>
<i>targetId</i> - id of target node.
<br><br>
<strong>To move node into position (to another tree)</strong>
<XMP>
tree.moveItem(nodeId,mode,targetId,targetTree)
</XMP>
<i>mode</i> possible values as above.<br>
<i>targetId</i> - id of target node (in target tree).<br>
<i>targetTree</i> - target tree object<br><br>
<strong>Cut/Paste way</strong><br>
Another way is to use doCut(),doPaste(id) - but this works with selected item only. Developer can also delete node in one place and create it in other (also the way ;-)).<br>
To give users the possibility to move items use drag-n-drop functionlity.
There is a possibility to display item children elements counter with the label of the node. To activate this feature use the following:
<XMP>
<script>
tree.setChildCalcMode(mode);
</script>
</XMP>
Possible modes are:<br>
<li>"child" - all childs on this level</li>
<li>"leafs" - all childs without subchilds on this level</li>
<li>"childrec" - all childs</li>
<li>"leafsrec" all childs without subchilds</li>
<li>"disabled" - nothing</li>
<br>
Other related methods:<br>
<strong>_getChildCounterValue(itemId)</strong> - get current counter value<br>
<strong>setChildCalcHTML(before,after)</strong> - html around counter to change default [x]<br>
Use <em>child</em> attribute in xml if you need to set counter value when using dynamical loading.
</div>
<aname="smartxml"><h4>Smart XML Parsing</h4></a><divclass="block">
The idea of Smart XML Parsing is simple - the entire tree structute loaded on client side, but only nodes which should be displayed are rendered. This helps to dramaticaly decrease loading time and general performance of large trees. Plus - in the contrary to Dynamical Loading - entrire tree structure is available for most of script methods (for example Search performed agains all nodes - not only rendered). To activate Smart XML Parsing use the following method:
<XMP>
<script>
tree.enableSmartXMLParsing(true);//false to disable
</script>
</XMP>
Smart XML Parsing do not work if tree loaded fully expanded.
</div>
<aname="checkbox"><h4>Checkboxes in tree</h4></a><divclass="block">
dhtmlxTree support two or three state checkboxes. Three state checkboxes means: checked/unchecked/some-child-checked (not all).
To enable three state checkboxes use the following method:
<XMP>
<script>
tree.enableThreeStateCheckboxes(true)//false to disable
</script>
</XMP>
Using three-state checboxes with smart xml parsing you need to specify third state manually (checked="-1"):
<xmp>
<itemchecked="-1"...>
<itemchecked="1".../>
<item.../>
</item>
</xmp>
Checkboxes can be disabled - <strong>disableCheckbox(id,state)</strong><br>
Some node can hide checkboxes - <strong>showItemCheckbox(id,state)</strong> (<strong>nocheckbox</strong> xml attribute)
There are three modes of drag-n-drop (set with <strong>setDragBehavior(mode)</strong>):<br>
<li>Drop as child - "child"</li><br>
<li>Drop as sibling - "sibling"</li><br>
<li>Complex mode (both previous are active) - "complex"</li><br>
Plus two modes of each of them:<br>
<li>1. Common drag-n-drop</li><br>
<li>2. Copy with drag-n-drop - <strong>tree.enableMercyDrag(1/0)</strong></li><br>
All modes can be changed on the fly.<br>
<br>
<h5>Event handlers</h5>
To process drag-n-drop before drop occured use onDrug event handler - <strong>setDragHandler(func)</strong>. If func doesn't return <em>true</em>, drop will be canceled.<br>
After drop occured there is another event - onDrop - handle it using setDropHandler(func).<br>
Both event handlers pass 5 parameters into the func object:<br>
<li>id of node which was dragged</li>
<li>id of target node</li>
<li>id of target-before node (if drop as sibling)</li>
<li>tree object source</li>
<li>tree object target</li>
</div>
<aname="dndifr"><h4>Drag-and-drop between iframes</h4></a><divclass="block">
Drag-n-drop between iframes enabled by default. All you need to do additionaly is to insert the following code into the page where no tree exists:<br>
Taking into account the general low performance of DHTML we introducrd two ways of increasing performance of large trees:<br>
1. <ahref="#dyntree">Dynamical Loading</a><br>
2. <ahref="#smartxml">Smart XML Parsing</a><br>
Also be sure your tree was organized well - putting a lot of items on one level of the branch makes tree difficalt for visual perception and decrease performance.
There is built in context menu in dhtmlxTree. The content of this menu can be set with XML or script. For changing context menu content depending on tree item developer can implement function for hidding/showing items of the same menu or associate different menues with different items. To enable context menu do the following:
Search functionality of dhtmlxTree allows moving focus on node with label fitting searchString mask.<br>
Has support for Smart XML Parsing.<br><br>
Script syntax:
<XMP>
tree.findItem(searchString); //find item next to current selection
tree.findItem(searchString,1,1)//find item previous to current selection
tree.findItem(searchString,0,1)//search from top
</XMP>
Example of usage is included in Professional Edition package <20> samples/treeExPro2.html.
</div>
<aname="multiline"><h4>Multiline tree items</h4></a><divclass="block">
...allows displaying tree items in multiline mode. For now it is recommended to turn tree lines off for better appearance. To enable multiline feature you need to do the following:
<XMP>
tree.enableTreeLines(false);
tree.enableMultiLineItems(true);
</XMP>
Example of usage is included in professional edition package <20> samples/treeExPro6.html.
</div>
<aname="g_icons"><h4>Icons in Tree</h4></a><divclass="block">
<h4>Set Icons</h4>
There is a way to set icons for the node explicetly using script (<strong>setItemImage,setItemImage2</strong>) or xml (<strong>im0,im1,im2</strong> attributes of item node):<br>
<li>im0 - item without children</li>
<li>im1 - closed item with children</li>
<li>im2 - opened item with children</li>
<h4>Set Icon Size</h4>
There is a way to set icon size for the whole tree or each node using script or xml:<br>
XML syntax for icon size per each item (optional):