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?
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.
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 )
dhtmlx.com/docs/products/kb/ … efreshItem
>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.
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 )
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
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?
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.
Replaced smartRefreshBranch with smartRefreshItem with same result - tree dissapears.
Please see the demo I sent (treeautodemo sent to support@dhtmlx.com ) this afternoon -
In index.html replace smartRefreshBranch with smartRefreshItem to see the problem
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.
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 -
> dhtmlx.com/docs/products/kb/ … efreshItem
>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 )
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.
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
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();
});
}
One more remark - tree.loadXML(“some.php”,…). Here some.php is the same as the script that is used to load root level initially.
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