Categories | Question details Back To List | ||
dhtmlxtree -performance: dynamic tree loading and refreshing current level With a large number of nodes its best not to load the whole tree and to use setXMLAutoLoading() to dynamically load hidden dhtmlxtree nodes on demand i.e. when expanding a dhtmlxtree node. But how do you combine this with being able to refresh the dhtmlxtree level you are already at? The dhtmlxtree corresponds to a directory tree on a server i.e. what if a new directory or file is created at the level you are at in the dhtmlxtree? Is it best to use tree.refreshItem/s or smartRefreshBranch or smartRefreshItem? What is the best for performance - time taken to refresh? Answer posted by Alex (support) on Nov 02, 2009 03:49 Hello, in case of dynamic loading you can use either refreshItem or smartRefreshItem method. Both methods refreshes the child nodes of an item that is set as an argument. Loading time is the same in both cases. But smartRefreshItem allows to restore the open state. So, it can load also sublevels (child items from the next levels) if they will be opened too.
Answer posted by Stephen on Nov 03, 2009 12:53 Alex, smartRefreshItem is not working ie doesn't see items deleted (from the server) I started with a script to create XML that contains all of server tree ie nodes/files 1) I have just root node X in dhtmlxtree (and server tree) 2) I create on the server subdir Y ie X/Y 3) I do a smartRefreshItem and I see X/Y in dhtmlxtree (ie loaded XML created from server dirs) 4) I delete X on the server and do a a smartRefreshItem and X/Y is still in dhtmlxtree If I replace smartRefreshItem with smartRefreshBranch the node is deleted from the tree. Now if I use setXMLAutoLoading then my script has now to only create XMLon one level i.e. not the whole tree and this works fine I can open/close dhtmlxtree nodes (that are on the server) but if I refresh using tree.smartRefreshBranch(0, xml script) then the dhtmlxtree dissappears (XML root node <tree id="0">) http://www.dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=3698&ssr=yes&s=smartRefreshItem >The smartRefreshItem functionality updates only single level of tree, if you need to update multiple levels at once you need to > use smartRefreshBranch ( which works nearly the same, but can update nested branches ) I want to 1) dynamically load the tree on demand using setXMLAutoLoading but also want to 2) be able to refresh dhtmlxtree to see if any new nodes have appeared or disappeared on the server for the nodes open in dhtmlxtree, so more than one level. Key to this is performance and I understand smartRefreshBranch: parses all the xml nodes completely. There can be browser performance issue if you try to parse a lot of nodes at once. Answer posted by Alex (support) on Nov 04, 2009 05:23 Hello, there are the answers to your question: >> I delete X on the server and do a a smartRefreshItem and X/Y is still in dhtmlxtree please, check that incoming xml contains only Y item. >> Now if I use setXMLAutoLoading then my script has now to only create XMLon one level i.e. not the whole tree and this works fine I can open/close dhtmlxtree nodes (that are on the server) but if I refresh using tree.smartRefreshBranch(0, xml script) then the dhtmlxtree dissappears (XML root node <tree id="0">) In case of dinamic loading you can call just tree.smartRefreshBranch(0) to refresh the tree. smartRefreshItem updates all levels in the autoloading is used. Please, provide the link to the problematic page if the problem still occurs. It can be also sent to support@dhtmlx.com Answer posted by Stephen on Nov 04, 2009 06:46 Problem still occurs - treeautodemo sent to support@dhtmlx.com with subject - dhtmlxtree -performance: dynamic tree loading and refreshing current level I stopped using refreshBranch because of performance problems - will this no longer be the case using setXMLAutoLoading - xml loaded by 'tree level' rather than loading the whole tree in?
Answer posted by Alex (support) on Nov 04, 2009 06:58 Sorry for misleading information, that was my typo. I meant smartRefreshItem instead of smartRefreshBranch: tree.smartRefreshItem(0) smartRefreshBranch updates the whole branch. And even you use dynamic loading it's necessary to load the whole tree structure if this method is used. For dynamic loading the best way is smartRefreshItem. Answer posted by Stephen on Nov 04, 2009 07:28 Replaced smartRefreshBranch with smartRefreshItem with same result - tree dissapears. Please see the demo I sent (treeautodemo sent to mailto:support@dhtmlx.com ) this afternoon - In index.html replace smartRefreshBranch with smartRefreshItem to see the problem Answer posted by Alex (support) on Nov 04, 2009 08:26 The answer will be sent by email. The reason for the issue is error in the server-side code that returns xml. The error occurs when id parameter is 0. Answer posted by Stephen on Nov 05, 2009 04:23 Alex are you sure about smartRefreshItem(0) as it only refreshes the top level id=0 ie you need to specifiy each level but I want to refresh all the visible parts of the dhtmlxTree Eg dhtmlxTree with just 1 node 'A' 1) Add another node B (server XML) same level as A and then smartRefreshItem(0 and B seen in dhtmlxTree Remove B (server XML) then smartRefreshItem(0 and B not seen in dhtmlxTree 2) Add 'A/X' then smartRefreshItem(0 and X not seen in dhtmlxTree 3) Add 'A/X/Y' then smartRefreshItem(0 and Y not seen in dhtmlxTree If I instead of the above I select X and call tree.smartRefreshItem(atree.getSelectedItemId()) then Y is seen in dhtmlxTree The above appears to agree with - > http://www.dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=3698&ssr=yes&s=smartRefreshItem >The smartRefreshItem functionality updates only single level of tree, if you need to update multiple levels at once you need to > use smartRefreshBranch ( which works nearly the same, but can update nested branches ) Answer posted by Stephen on Nov 05, 2009 04:41 Forget to add that when I refresh ie tree.smartRefreshItem(0); I can see in FF the correct url with "?id=0" but my php code only returns the XML for level id=0 I've looked at dhtmlxTree/samples/12_loading_processing_data/11_pro_smart_refresh.html and noticed that it makes one call using "?id=0" to refresh the whole tree but it collapses the tree to the top level not what I want, I want the tree to stay expanded. Answer posted by Stephen on Nov 05, 2009 04:58 I want to refresh the visible tree with whatever nodes that are open. I do not see how tree.smartRefreshItem(0); can do this as all it appears to do is refresh the top level. The sample 11_pro_smart_refresh.html does just that the xml.php simply generates 4 nodes per level. So I think I have to give up on dynamic loading and 1 load the whole tree on start up and 2 for a refresh save the tree state delete tree load tree restore state Answer posted by Alex (support) on Nov 05, 2009 05:01 Hello, yes, you're right regarding smartRefreshItem. Please, try to use the following approach instead. This approach will works with dynamic loading: function refresh(){ /*saves open states*/ tree.saveOpenStates(); /*reload tree*/ tree.deleteChildItems(0); tree.loadXML("some.php",function(){ /*restores open states after root xml loading*/ tree.loadOpenStates(); }); } Answer posted by Alex (support) on Nov 05, 2009 05:04 One more remark - tree.loadXML("some.php",...). Here some.php is the same as the script that is used to load root level initially. Answer posted by Stephen on Nov 05, 2009 07:36 Thanks Alex, so I can dynamically 1 load tree - loadXML tree at first level and use setXMLAutoLoading to load on demand when nodes are opened 2 refesh tree - save tree state ,delete tree, loadXML tree at first level, load saved tree state |