The following ways of increasing performance when working with huge data sets are introduced in dhtmlxTree:
In case Tree contains large amount of nodes (or the user doesn't want to waste time on loading hidden nodes), it would be better to load them on request, not all at once.
The functionality to load tree's levels dynamically using XML was introduced for this purpose. Dynamic loading of items from XML stream gives the possibility to create DHTML trees with unlimited number of nodes.
Firstly, the user should indicate in XML the nodes that will be loaded dynamically in this way: add the parameter child="1" to all nodes that have child items. The items containing this parameter will be the objects for dynamic loading.
<?xml version="1.0" encoding="iso-8859-1" ?>
<tree id="0">
<item text="Surveillance" id="a1" im0="book.gif" … child="1"/>
<item …/>
…
</tree>
The setXMLAutoLoading method switches the dynamic loading on in the tree:
tree.setXMLAutoLoading(url);
tree.load(file); // load the first level of the tree
The above mentioned snippet is useful in case of a tree with large amount of data.
The system will firstly load the data indicated by the load() method.
The script specified in the setXMLAutoLoading() method will be called when the user clicks the tree to expand any of the parent nodes (the child nodes of which have not been loaded). The script will get the id of the node to open, and return an XML with the description of child items.
When dynamic loading is switched on in the tree, script methods work only for those items that are loaded at the moment.
Related sample: Autoloading from XML
This functionality is available in the PRO version only.
The setXMLAutoLoadingBehaviour method is responsible for specifying the way according to which the server-side URL is constructed during dynamic loading calls:
tree.setXMLAutoLoadingBehaviour(mode);
The following mode options are available here:
An example of using the function mode may look as follows:
tree.setXMLAutoLoadingBehavior("function");
tree.setXMLAutoLoading(function(id){
tree.load("some.php?id="+id)
})
In this mode the setXMLAutoLoading() method receives a function that sends a request to the script to load the content of the clicked item by its id. The load() method called inside of this function returns an XML with the description of child items of the clicked item.
Related sample: Operations in a dynamic tree
The setEscapingMode() method is responsible for setting the escaping mode (used for escaping id in requests). This method sets the mode for transferring the information of tree's item to the server:
tree.setEscapingMode(mode);
The following modes are available:
The idea of Smart XML Parsing is simple: the entire tree structure is loaded on the client side, but only the nodes that should be displayed are rendered. It helps to decrease the loading time and enhance the general performance of large trees greatly. Plus, the entire tree structure is available for most of the script methods (for example, searching is performed through all the nodes, not only through the rendered ones).
To activate Smart XML Parsing the user should apply the following method:
tree.enableSmartXMLParsing(true); // false is used to disable
Please, pay attention to the fact that Smart XML Parsing does not work in case of loading a fully expanded tree.
Related sample: Smart XML parsing
The parsing state can be got by means of the getItemParsingState() method which takes an item's id as the parameter:
var state = tree.getItemParsingState(itemId);
The method returns:
Another way of increasing the performance of the tree with some levels containing more than 100-200 nodes per level is introduced. This functionality is called Distributed Parsing.
The main advantage of this functionality lies in making a level visible and ready to use before it is completely parsed. Thus, items are loaded portion by portion with some timeouts.
To enable this functionality the user should make use of the following JS command:
tree.enableDistributedParsing(mode,count,delay);
Parameters of this method are:
This functionaity is fully compatible with Smart XML Parsing.
Related sample: Distributed parsing
The current state of Distributed Parsing can be easily got in the following way:
var state = tree.getDistributedParsingState(); // returns true/false
This method returns either true (meaning that parsing is still in progress) or false (meaning that parsing is already finished).
Back to top