• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2392
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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