Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by John-Olav Hoddevik on May 26, 2008 06:37
open dhtmlx forum
Refresh Branch

I need to refresh a branch of a tree. I've tried refreshItem, this creates a duplicate of the branch. I've tried smartRefreshitem, and smartRefreshBranch but nothing happens. I'm however able to refresh the entire tree.

This is my code for initiating the tree:
tree4=new dhtmlXTreeObject(document.getElementById('treeBox_4'),"100%","",0);
tree4.setImagePath("js/dhtmlxTree/codebase/imgs/csh_vista/");
tree4.enableCheckBoxes(false);
tree4.setOnClickHandler(doOnClick4);
tree4.preventIECaching(true);
tree4.setXMLAutoLoading("...");
tree4.loadXML("...");
Answer posted by Support on May 26, 2008 10:21
The code is correct and must not cause any problem.
Are you using refreshItem agains opened branch, or agains one, which never was loaded from server yet?
In second case problem with duplication may really occurs ( the XML will be loaded twice - one by refreshItem command, second automatically while opening item )

You can try to use next code snippet
if (tree.hasChildren(id) === true)
    tree.openItem(id);
else
    tree.refreshItem(id);

It will open item if it was never opened before, and will call refreshItem if item was already loaded.
Such approach must prevent duplication.
Answer posted by John-Olav Hoddevik on May 26, 2008 11:16
I'm always refreshing an open branch.

Well, refreshItem() actually works on branches, but it has the unwanted sideeffect that it duplicates the top-level items. I tried using smartRefreshItem but nothing seems to happen(?)
Answer posted by Support on May 27, 2008 01:32
Both smartRefreshItem and smartRefreshBranch commands updated items in tree based on their IDs.
Please be sure that
    a) response XML has tree@id pointed to updated branch ID
    b) the item@id in response XML must be the same as IDs of items , which need to be updated