This is a migrated thread and some comments may be shown as answers.

Add root nodes on client

3 Answers 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 08 Dec 2011, 09:52 AM
Hi,

in certain cases I want to reload specific nodes. When it's about nodes under other nodes, this is no problem.
I collapse the node, remove the children, set the expand mode back to webservice and expand the node.
The nodes are loaded-on-demand by the tree.

But when it is about the root nodes, I have to do it myself. I call the webservice, get the nodes but how do I add them to the tree?
This is what I found in the forums (but the post was from 2008).
function AddRootNodesToTree(nodes, tree) {
   tree.trackChanges();
   tree.get_nodes().clear();
   for (var node in nodes) {
      var dynamicNode = new Telerik.Web.UI.RadTreeNode();
      dynamicNode._loadFromDictionary(nodes[node]);
      tree.get_nodes().add(dynamicNode);
   }
   tree.commitChanges();
}

The nodes from the webservice are correctly converted to RadTreeNode and added. But the attributes of the nodes aren't transferred to the RadTreeNode.

So, how can I add nodes, which I fetch from a webservice, to the tree as root nodes?

Thanks!

Edit: I added screenshot from the Google Chrome debugger where you can see the difference. The webservice returns in both cases RadTreeNodeData and I didn't see any difference regarding the attributes.

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 13 Dec 2011, 12:39 PM
Hello Jp,

I inspected the issue but the scenario is not very clear and I will need some more information. Would you please specify from where do you take the "nodes" collection and post the code related with it?

Would you please explain as well why are you using the "._loadFromDictionary" and which is the forum post that you are using?

Regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
JP
Top achievements
Rank 1
answered on 13 Dec 2011, 02:42 PM
Hi,

this is the thread from where I got the information:
http://www.telerik.com/community/forums/aspnet-ajax/treeview/adding-a-node-client-side-from-a-webservice.aspx 

I have a webservice which returns the nodes: 
public RadTreeNodeData[] GetHierarchyTreeRootNodes(string connectionId, string context)
{
         return FmHierarchyAjaxTreeWebserviceFunctions.GetRootNodes(connectionId, context);
}

The webservice is called whenever it is necessary to reload the root nodes:

var connectionId = node.get_attributes().getAttribute("ConnectionId");
var context = node.get_attributes().getAttribute("ConfigurationContext");
      WebServices.IGeneralAjaxServices.GetHierarchyTreeRootNodes(connectionId, context, ApplyNodesToTree, ApplyNodesToTree, tree);

The javascript callback function is the function I posted in the first post. The nodes parameter of the function is the return value from the webservice.
0
Plamen
Telerik team
answered on 16 Dec 2011, 03:46 PM
Hi Jp,

I have inspected furthermore this scenario. It came out that when WebService load on demand is used only child nodes can be added and adding root nodes is not supported when they are not created in advance.

Hope this will be helpful.

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeView
Asked by
JP
Top achievements
Rank 1
Answers by
Plamen
Telerik team
JP
Top achievements
Rank 1
Share this question
or