I need to create multiple node levels down in WebDataTree on client side using javascript.
Here is what I need:
->Parent 1
-> Child1
-->Child 2
---> Child4
Here is the code I use:
for (var i = 0; i < 5; i++) { child_node = wdtTREE.createNode("Child1"); if (i==0) { parent_node.getItems().add(child_node); }
parent_node.Expanded = true; parent_node.Selected = true; child_node.ExpandAnscestors(); parent_node = child_node; }
When I use this code, It is creating the first node under Parent. After that in the loop when i=2, it cannot add and I'm getting this error.
0x800a138f - JavaScript runtime error: Unable to get property 'add' of undefined or null reference
Please assist.
Hello Naveen,
Thank you for using our community.
Please refer to the following treads and samples that I believe can be useful for your case:
http://es.infragistics.com/community/forums/t/51266.aspx
http://es.infragistics.com/community/forums/t/67799.aspx
Online sample:
http://es.infragistics.com/samples/aspnet/data-tree/using-client-side-api
Online documentation:
http://help.infragistics.com/Doc/ASPNET/Current/CLR4.0?page=WebDataTree~Infragistics.Web.UI_namespace.html
If you need further assistance, please let me know.
Hello Marina,
I have checked all the links that you suggested earlier. But those does not help my purpose.
Can you provide me an example for my requirement. I'm able to add nodes at the parent level. But when I convert child node to be a parent node and add one more node under it, I'm not able to do it.
Please advice.
I have created a sample for you that demonstrates how to create a simple hierarchical tree. Please take a look at it and let me know if you have further questions.
Thank you for giving me more details on your case.
I used your approach and made some changes. The error that you are receiving is due to that you add a child to a node that is not initialized. Here is the updated code snippet, please try it and let me know how it works for you.
var tree = $find('<%=WebDataTree1.ClientID %>');
var child, parent;
parent = tree.createNode("Root1");
parent = tree.add(parent);
for (var i = 0; i < 5; i++) {
//add custom logic
child = tree.createNode("Child");
child = parent.getItems().add(child);
parent = child;
}
This example is the same as one of the link.
The node that I'm adding to the tree is dynamic and can be at 3 or 4 levels down the tree and I will need to create node 1 node under each node with the same node text until level 10.
XYZ (Home)
-->ABC TEST
-->Test node
--> Test node
etc...
So I'm expecting to add child to the node. Not to the tree at a specific position.