• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2196
  • Last Modified:

i want to find the parent node in treeview using javascript

hello i am create asp.net web application using C#.net

i want to find the parent node of the new node if its exist then add to the another treeview here is the sample code given below

the classes node is statically define in the treeview..

kindly help me how could i find the node parent and then insert in the snode

thanks
function ClassNodeEdit(sender, eventArgs) {
               var node1 = eventArgs.get_node();
                var nodeText = node1.get_text();


                var tree = $find("tree_test");
                var snode = tree.findNodeByText("Classes");

                tree.trackChanges();




                var node = new Telerik.Web.UI.RadTreeNode();
                node.set_text(node1.get_text());
                snode.get_nodes().add(node);
                tree.commitChanges();
            }

Open in new window

0
AVARICESOFT
Asked:
AVARICESOFT
  • 3
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
just use get_parent():
for example:

function GetParent()
{
   var tree= $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByAttribute("MyCustomAttribute", "Some Value");
   node.get_parent().expand();
   node.select();
}




u can use this link for treeview api:
http://www.telerik.com/help/aspnet-ajax/tree_clientradtreenode.html
0
 
Meir RivkinFull stack Software EngineerCommented:
so in your case it would be something like this:

var tree = $find("tree_test");
                var snode = tree.findNodeByText("Classes");


var node = new Telerik.Web.UI.RadTreeNode();
                node.set_text(snode.get_parent().get_text());
                snode.get_nodes().add(node);
                tree.commitChanges();
0
 
Meir RivkinFull stack Software EngineerCommented:
sorry i misused your code, i though the snode is the one ur looking for.
u probably familiar with your code more than i, so if get_parent() doesn't work for you let me know.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Saber37886661Commented:
Argh, not Telerik controls :/
Honestly its easier doing it on a ajax post back, but if you really want it in javascript I would suggest the following. Of course this could be broken depending on the release you are using.

The example will add a new node with the text in the var 'nodeText'.

The second example will find th enode for you



function addNode()
{
    var nodeText = "what text you want for the node";
    treeView.trackChanges();
    var node = new Telerik.Web.UI.RadTreeNode();
    node.set_text(nodeText);
//Add the new node as the child of the selected node or the
//treeview if no node is selected
    var parent = treeView.get_selectedNode() || treeView;
    parent.get_nodes().add(node);
//Expand the parent if it is not the treeview
    if (parent != treeView && !parent.get_expanded())
    parent.set_expanded(true);
    treeView.commitChanges();
    return false;
}


To find the text of a certain node do this:
treeView = $find ("<%= RadTreeView1.ClientID %>");
var allNodes = treeView.get_allNodes();
for (var i = 0; i < allNodes.length; i++)
{
    if(args.get_node().get_text())==searchText)
    {
        alert("Found the node....now what?!?! :)";
    }
}

Open in new window

0
 
AVARICESOFTAuthor Commented:
hey man ur are almost right but kindly give me code of that suppose:

i have 1 RadTreeView1 and 2nd RadTreeView2

i only want to add the node which is added on the RadTreeView1 by hierarchy ..

this function automatically call when RadTreeView1 node created dynamically

function ClassNodeEdit(sender, eventArgs) {
}

i only want to copy the nodes from RadTreeView1 to RadTreeView2 according to hieracry like parents is parent and child is child nothing more..  but in javascript clientside

the ClassNodeEdit function is called when the RadTreeView1 Node is create...

Thanks.

0
 
AVARICESOFTAuthor Commented:
thanks i get the solution
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now