New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

RadTreeNode

The table below lists the most important function of the RadTreeNode object.

When setting a property to a node via the methods below, first make sure that the node is already added to the TreeView to prevent JavaScript errors on the page.

 

NameParametersReturn TypeDescription
findControlStringObjectReturns the client-side object of the Control with the specified ID nested in the Node's Template. The ID passed as an argument to the function MUST be the ID attribute of the nested Control.
toJsonStringnonestringReturns the JSON representation of the node (serialize the node as a string in JSON format).
get_previousNodenoneRadTreeNodeGets an instance of the previous sibling of a Node. (see Example 1)
get_nextNodenoneRadTreeNodeGets an instance of the next sibling of a Node. (see Example 2)
expand & collapsenonenoneexpand() opens a Node to display child Nodes. collapse() closes a Node to hide child Nodes. (see Example 3)
set_expandedboolnoneExpands or collapses a Node. (see Example 4)
togglenonenoneCollapses an expanded Node or expands a collapsed Node. (see Example 5)
highlight & unhighlightnonenoneHighlights or un-highlights a Node. Highlighted Nodes are visually emphasized. The specific display is dictated by the Skin. (see Example 6)
select & unselectnonenoneSelect or unselect a Node. Selecting a Node typically emphasizes the Node. The specific display is dictated by the Skin. Highlighting and selecting have similar but not identical displays.If selecting a Node with a mouse does postback, calling the select() function will select the Node and do postback. (see Example 7)
set_selectedboolnoneSelects or unselects a Node based on the boolean parameter.If selecting a Node with a mouse does postback, calling the set_selected(true) function will select the Node but will NOT do postback. (see Example 8)
enable & disablenonenonedisable() makes a Node inactive and unclickable. Typically the Node is displayed in a lighter color dictated by the style setting of the Skin. enable() returns the Node to a usable, clickable state. disable is a functionally equivalent to set_enabled(false) and enable() is equivalent to set_enabled(true). (see Example 9)
set_enabledboolnoneEnables or disables a Node based on the boolean parameter passed in. set_enabled(false) is a functionally equivalent to disable() and set_enabled(true) is equivalent to enable(). (see Example 10)
check & unchecknonenoneMarks or unmarks the checkbox for a Node. check() is a functionally equivalent to set_checked(true) and uncheck() is equivalent to set_checked(false); (see Example 11)
set_checkedboolnoneMarks or unmarks the checkbox for a Node. check() is a functionally equivalent to set_checked(true) and uncheck() is equivalent to set_checked(false); (see Example 12)
get_checkStatenoneTelerik.Web.UI.TreeNodeCheckStateReturns the current check state of a node. It can be one of the following:Telerik.Web.UI.TreeNodeCheckState.Unchecked, Telerik.Web.UI.TreeNodeCheckState.Checked or Telerik.Web.UI.TreeNodeCheckState.Indeterminate
startEditnonenoneAllows the Node to be edited. This is equivalent to the userclicking the Node twice or pressing F2. (see Example 13)
endEditnonenoneTakes the Node out of editing mode. (see Example 14)
get_checkBoxElementnoneDOM ElementGets the DOM Element of the checkbox. (see Example 15)
scrollIntoViewnonenoneCauses the Node to scroll into view, aligning the Node to the bottom of the TreeView area. This function repositions the TreeView's scrollbars, not the scrollbars for the page itself. (see Example 16)
get_imageElementnoneDOM ElementGets the DOM Element of the image set to the node. Note: Images are set using the RadTreeView ImageUrl property. (see Example 17)
get_textElementnoneDOM ElementGets the DOM Element of the text set to the Node. Note : Changes to the text element are not persisted across postbacks. (see Example 18)
get_textnonestringRetrieves the text for a Node. (see Example 19)
set_textstringnoneSets the text of the Node.
get_valuenonestringGets the value of the Node.
set_valuestringnoneSets the value of the Node. (see Example 20)
get_categorynonestringGets the category of the Node.
set_categorystringnoneSets the category of the Node. (see Example 21)
get_isEnablednoneboolReturns true if both the Node and the tree are enabled. If one of them is disabled, the get_isEnabled returns false.
get_enablednoneboolGets the enabled state of the Node. The Node is enabled if get_enabled() returns true. (see Example 22)
get_expandednoneboolGets the expanded/collapsed state of a Node. The Node is expanded if get_expanded() returns true. (see Example 23)
get_checkednoneboolGets the checked state of a Node. The Node is checked if get_checked() returns true. (see Example 24)
get_selectednoneboolGets the selected state of a Node. Returns true if the Node is selected. (see Example 25)
get_nodesnoneTelerik.Web.UI.RadTreeNodeCollectionReturns the RadTreeNodeCollection of a Node. (see Example 26)
get_allNodesnonearray of RadTreeNode objectsReturns all child nodes of a Node. (see Example 27)
get_parentnoneRadTreeNode/RadTreeViewGets an instance of the parent-Node or the RadTreeView object if the Node is a root Node. (see Example 28)
get_treeViewnoneRadTreeViewGets an instance to the parent RadTreeView. The example below retrieves the TreeView and calls various methods from the TreeView. (see Example 29)
get_elementnoneDOM ElementReturns the DOM element for a Node. (see Example 30)
get_contextMenunoneRadMenuReturns the context menu object (if any). (see Example 31)
get_navigateUrlnoneStringReturns the URL of the Node(the href attribute of the link). Null if the NavigateUrl server property is not set.
set_navigateUrlStringnoneSets the URL of the Node. Works only if the NavigateUrl property has been set at the server-side beforehand or if the Node is not added at the client-side. (see Example 32)
get_attributesnoneCollectionReturns a Collection of all custom attributes set to the Node. (see Example 33)
set_targetStringnoneSets the target of the Node.
get_targetnoneStringGets the target of the Node. If a target is not set, returns null .
set_toolTipStringnoneSets the ToolTip of the Node.
get_toolTipnoneStringGets the ToolTip of the Node. If a ToolTip is not set, returns null .
get_levelnoneIntegerGets the Level of the Node in the TreeView structure. Root Nodes are at level 0, their children Nodes - at 1 and so on.
set_checkableBooleannoneEnables/Disables the checkability of the Node.
get_imageUrlnoneStringReturns the path to the image displayed next to the Node.
set_imageUrlStringnoneSets the path to the image displayed next to the Node.
get_disabledImageUrlnoneStringReturns the path to the image displayed next to the Node when disabled.
set_disabledImageUrlStringnoneSets the path to the image displayed next to the Node when disabled.
get_expandedImageUrlnoneStringReturns the path to the image displayed next to the Node when expanded.
set_expandedImageUrlStringnoneSets the path to the image displayed next to the Node when expanded.
get_selectedImageUrlnoneStringReturns the path to the image displayed next to the Node when selected.
set_selectedImageUrlStringnoneSets the path to the image displayed next to the Node when selected.
get_hoveredImageUrlnoneStringReturns the path to the image displayed next to the Node when hovered.
set_hoveredImageUrlStringnoneSets the path to the image displayed next to the Node when hovered.
get_cssClassnoneStringReturns the name of the CSS class applied to the Node.
set_cssClassStringnoneSets the name of the CSS class to be applied to the Node.
get_disabledCssClassnoneStringReturns the name of the CSS class applied to the Node when disabled.
set_disabledCssClassStringnoneSets the name of the CSS class to be applied to the Node when disabled.
get_hoveredCssClassnoneStringReturns the name of the CSS class applied to the Node when hovered.
set_hoveredCssClassStringnoneSets the name of the CSS class to be applied to the Node when hovered.
get_childListElementnoneHTML ElementReturns the UL HTML element which contains the HTML elements of the child Nodes. Null if there are no child Nodes.
get_contextMenuIDnoneStringReturns the ID of the Context Menu assigned to the Node.
set_contextMenuIDStringnoneSets the ID of the Context menu to be assigned to the Node.
get_toggleElementnoneHTML ElementReturns the HTML element representing the toggle image. Null, if the Node has no child Nodes.
get_enableContextMenunoneBooleanTrue if the Context Menus are enabled, False otherwise.
showLoadingStatusstatusText, positionnoneShows the loading message at the specified position. The available positions are: Telerik.Web.UI.TreeViewLoadingStatusPosition.BelowNodeText Telerik.Web.UI.TreeViewLoadingStatusPosition.AfterNodeText Telerik.Web.UI.TreeViewLoadingStatusPosition.BeforeNodeText (see Example 34)
hideLoadingStatusnonenoneHides the loading message.
get_postBacknoneBooleanTrue if postback is enabled, false otherwise.
set_postBackBooleannoneDetermines if the Node should postback.
get_expandModenoneIntReturns the ExpandMode of the Node.ExpandMode can be:0 - ExpandMode.ClientSide;1 - ExpandMode.ServerSide;2 - ExpandMode.ServerSideCallBack;3 - ExpandMode.WebService;
set_expandModeExpandModenoneSets the ExpandMode of the Node.ExpandMode can be:Telerik.Web.UI.TreeNodeExpandMode.ClientSide;Telerik.Web.UI.TreeNodeExpandMode.ServerSide; Telerik.Web.UI.TreeNodeExpandMode.ServerSideCallBack;Telerik.Web.UI.TreeNodeExpandMode.WebService;
get_visiblenoneBooleanTrue if the item is visible.
set_visibleBooleannoneSets the visibility of the item. (see Example 35)
get_allowEditnoneBooleanTrue, if Node edit is allowed, false, otherwise.
set_allowEditBooleannoneAllows/Disallows Node editing.
get_allowDragnoneBooleanTrue, if dragging is allowed, false otherwise.
set_allowDragBooleannoneEnables/Disables dragging.
get_allowDropnoneBooleanTrue, if dropping is allowed, false otherwise.
set_allowDropBooleannoneEnables/Disables dragging.
get_indexnoneintReturns the index of the node in the nodes collection of its parent.

Example 1: Demonstrates the usage of the get_previousNode method

JavaScript
function PreviousNode()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Child RadTreeNode 2");
   if(node)
   {
       var prevNode = node.get_previousNode();
       prevNode.get_parent().expand();
       prevNode.select();
   }
}

Example 2: Demonstrates the usage of the get_nextNode method

JavaScript
function GetNextNode()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Child RadTreeNode 1");
   if(node)
   {
       var prevNode = node.get_nextNode();
       prevNode.get_parent().expand();
       prevNode.select();
   }
}		

Example 3: Demonstrates the usage of the expand/collapse methods

JavaScript
function ExpandNode()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       node.expand();
       //node.collapse();
   }
}     

Example 4: Demonstrates the usage of the set_expanded method

JavaScript
function SetExpanded()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_expanded())    
       {       
           node.set_expanded(false);    
       }    
       else    
       {       
           node.set_expanded(true);     
       }          
   }
}		

Example 5: Demonstrates the usage of the toggle method

JavaScript
function ToggleNode()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       node.toggle();
   }
}		

Example 6: Demonstrates the usage of the highlight/unhighlight methods

JavaScript
function HighlightNode()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       node.highlight();
       //node.unhighlight();
   }
}		

Example 7: Demonstrates the usage of the select/unselect method

JavaScript
function SelectNode()
{
   var tree= $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if (node)
   {
       if (node.get_selected())
       {
           node.unselect();
       }
       else
       {
           node.select();
       }
   }  
}		

Example 8: Demonstrates the usage of the set_selected method

JavaScript
function SetSelected()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_selected())    
       {       
           node.set_selected(false);    
       }    
       else    
       {       
           node.set_selected(true);     
       }          
   }
}

Example 9: Demonstrates the usage of the enable/disable method

JavaScript
function SetEnabled()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_enabled())    
       {        
           node.disable();     
       }    
       else    
       {          
           node.enable();
       }          
   }
}	

Example 10: Demonstrates the usage of the set_enabled method

JavaScript
function SetEnabled()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_enabled())    
       {       
           node.set_enabled(false);
       }    
       else    
       {       
           node.set_enabled(true);     
       }          
   }
}		

Example 11: Demonstrates the usage of the check/uncheck method

JavaScript
function SetChecked()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_checked())    
       {       
           //node.set_checked(false);      
           node.uncheck();      
       }    
       else    
       {       
           //node.set_checked(true);
           node.check();
       }          
   }
}		

Example 12: Demonstrates the usage of the set_checked method

JavaScript
function SetChecked()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_checked())    
       {        
           node.set_checked(false);      
           //node.uncheck();      
       }    
       else    
       {       
           node.set_checked(true);
           //node.check();
       }          
   }
}		

Example 13: Demonstrates the usage of the startEdit method

JavaScript
function Edit()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       node.set_text("Rename this node");
       node.startEdit();         
   }
}		

Example 14: Demonstrates the usage of the endEdit method

JavaScript
var text;
function Edit()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       text = node.get_text();
       node.startEdit();         
   }
}
function EndEdit()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if (node.get_text() != text)
       {
           node.endEdit();        
       }
       else
       {
           alert("no changes were made");
       }
   }
}		

Example 15: Demonstrates the usage of the get_checkBoxElement method

JavaScript
function GetCheckBoxElement()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       alert(node.get_checkBoxElement().className);
   }
}		

Example 16: Demonstrates the usage of the scrollIntoView method

JavaScript
function ScrollNode()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("My Node");
   if(node)
   {
       node.scrollIntoView();
   }
}		

Example 17: Demonstrates the usage of the get_imageElement method

JavaScript
function GetImageElement()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");       
   var node = tree.get_selectedNode();
   if(node)
   {
       alert(node.get_imageElement().src);
   }
}		

Example 18: Demonstrates the usage of the get_textElement method

JavaScript
function GetTextElement()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");       
   var node = tree.get_selectedNode();
   if(node)
   {
       alert(node.get_textElement().innerHTML);
   }
}		

Example 19: Demonstrates the usage of the get_text method

JavaScript
function GetText()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");       
   var node = tree.get_selectedNode();
   if(node)
   {
       alert(node.get_text());
   }
}		

Example 20: Demonstrates the usage of the get_value method

JavaScript
function GetValue()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");       
   var node = tree.get_selectedNode();
   if(node)
   {
       alert(node.get_value());
   }
}		

Example 21: Demonstrates the usage of the get_category method

JavaScript
function GetCategory()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");       
   var node = tree.get_selectedNode();
   if(node)
   {
       alert(node.get_category());
   }
}		

Example 22: Demonstrates the usage of the get_enabled method

JavaScript
function GetEnabled()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_enabled())    
       {       
           node.set_enabled(false);   
       }    
       else    
       {       
           node.set_enabled(true);      
       }          
   }
}		

Example 23: Demonstrates the usage of the get_expanded method

JavaScript
function GetExpanded()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_expanded())    
       {       
           node.set_expanded(false);    
       }    
       else    
       {       
           node.set_expanded(true);     
       }          
   }
}		

Example 24: Demonstrates the usage of the get_checked method

JavaScript
function GetChecked()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_checked())    
       {       
           node.set_checked(false);          
       }    
       else    
       {       
           node.set_checked(true);
       }          
   }
}		

Example 25: Demonstrates the usage of the get_selected method

JavaScript
function GetSelected()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node = tree.findNodeByText("Root Node 1");
   if(node)
   {
       if(node.get_selected())    
       {       
           node.set_selected(false);    
       }    
       else    
       {       
           node.set_selected(true);     
       }          
   }
}		

Example 26: Demonstrates the usage of the get_nodes method

JavaScript
function GetNodes()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var node0 = tree.get_nodes().getNode(0);
   for (var i=0; i < node0.get_nodes().get_count();i++)  
   {        
       var node = node0.get_nodes().getNode(i);        
       alert(node.get_text());  
   }
}		

Example 27: Demonstrates the usage of the get_allNodes method

JavaScript
function GetNodes()
{
   var tree = $find("<%= RadTreeView1.ClientID %>");
   var allNodes = tree.get_nodes().getNode(0).get_allNodes();
   for (var i=0; i < allNodes.length; i++)  
   {        
       var node = allNodes[i];        
       alert(node.get_text());  
   }
}		

Example 28: Demonstrates the usage of the get_parent method

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

Example 29: Demonstrates the usage of the get_treeView method

JavaScript
function GetTreeView(node) {
    if (node) {
        var tree = node.get_treeView();
        var nodeText = node.get_text();

        tree.trackChanges();
        // remove duplicates of node
        var foundNode = tree.findNodeByText(nodeText);
        while (foundNode) {
            tree.get_nodes().remove(foundNode)
            foundNode = tree.findNodeByText(nodeText);
        }

        // add selected node back in
        tree.get_nodes().add(node);

        tree.commitChanges();
    }
}		

Example 30: Demonstrates the usage of the get_element method

JavaScript
function GetNodeElement() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var node = tree.get_selectedNode();
    if (node) {
        alert(node.get_element().innerHTML);
    }
}

Example 31: Demonstrates the usage of the get_contextMenu method

JavaScript
function GetContextMenu() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var node = tree.get_selectedNode();
    if (node) {
        var menu = node.get_contextMenu();
        if (menu)
            menu.hide();
    }
}			

Example 32: Demonstrates the usage of the set_navigateUrl method

JavaScript
function setNavigateUrlToTheSelectedNode() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var node = tree.get_selectedNode();
    if (node) {
        node.set_navigateUrl("http://www.example.com");
    }
}			

Example 33: Demonstrates the usage of the get_attributes method

JavaScript
function getCustomAttributes() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var node = tree.get_selectedNode();
    if (node) {
        var attributes = node.get_attributes();
        attributes.setAttribute("AttributeName", AttributeValue);
        var attribute1 = attributes.getAttribute("AttributeName");

    }
}		

Example 34: Demonstrates the usage of the showLoadingStatus method

JavaScript
node.showLoadingStatus("Loading…", Telerik.Web.UI.TreeViewLoadingStatusPosition.BelowNodeText);

Example 35: Demonstrates the usage of the set_expandMode method

JavaScript
node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.WebService);

See Also

In this article
See Also
Not finding the help you need?
Contact Support