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

RadTreeView

The table below lists the most important functions of the client-side RadTreeView object. Many significant functions for performing common tasks such as adding, inserting and removing Nodes are actually performed using the RadTreeNodeCollection object.

Client side changes are available on the server side after postback. You can use the ClientChanges property to access them.

 

NameParametersReturn TypeDescription
trackChangesnonenoneStarts tracking changes made to the TreeView that will be preserved on the server.
commitChangesnonenoneWrites the changes to the TreeView that were made since a previous call to trackChanges, so that they are preserved on the server as well.(see Example 1)
findNodeByTextstringRadTreeNodeGets the first instance of a Node with the specified text. (see Example 2)
findNodeByValuestringRadTreeNodeGets the first instance of a Node with the specified value. (see Example 3)
findNodeByAttributestring (attribute name), string (attribute value)RadTreeNodeGets the first instance of a Node with the specified attribute, value pair. (see Example 4)
findNodeByUrl(string URL)RadTreeNodeReturns the first RadTreeNode object whose NavigateUrl property is equal to the passed parameter.
findNodeByAbsoluteUrl(string URL)RadTreeNodeReturns the first RadTreeNode object whose NavigateUrl property is equal to the passed parameter. Note that the parameter should ends with '/' like:var item = sender.findNodeByAbsoluteUrl('http://www.test.com/');
get_selectedNodesnoneArrayGets an Array of all selected Nodes (useful when MultipleSelect property is on). (see Example 5)
unselectAllNodesnonenoneUn-selects all Nodes at all levels of the tree. (see Example 6)
get_nodesnoneTelerik.Web.UI.RadTreeNodeCollectionReturns the root level RadTreeNodeCollection. This example iterates the root level Nodes. (see Example 7)
get_allNodesnoneArray of RadTreeNode objectsReturns an array of all the Nodes within the TreeView. (see Example 8)
get_selectedNodenonenoneGets the instance of the currently selected Node. Null if none. (see Example 9)
get_idnonestringGets the server ID of the control. (see Example 10)
get_elementnoneDOM ElementGets a reference to the DIV element that wraps the TreeView. (see Example 11)
get_enablednoneBooleanGets the enabled state of the TreeView.
set_enabledBooleannoneEnables/Disables the TreeView. (see Example 12)
get_loadingMessagenoneStringReturns the value of the RadTreeView's LoadingMessage property. The default value is "Loading..."
set_loadingMessageStringnoneSets a loading message to the TreeView. (see Example 13)
get_childListElementnoneHTML ElementReturns the UL HTML element which contains the HTML elements of the root Nodes. Null if there are no root Nodes.
get_allowNodeEditingnoneBooleanTrue if the AllowNodeEditing property is enabled, false otherwise.
set_allowNodeEditingBooleannoneEnables/Disables Node-editing.
get_enableDragAndDropnoneBooleanTrue if the EnableDragAndDrop property is enabled, false otherwise.
set_enableDragAndDropBooleannoneEnables/Disables drag and drop.
get_enableDragAndDropBetweenNodesnoneBooleanTrue if the EnableDragAndDropBetweenNodes property is enabled, false otherwise.
set_enableDragAndDropBetweenNodesBooleannoneEnables/Disables the drag and drop between Nodes.
get_persistLoadOnDemandNodesnoneBooleanTrue if the PersistLoadOnDemandNodes property is enabled, false otherwise.
set_persistLoadOnDemandNodesBooleannoneEnables/Disables the persistence (at the server-side) of Nodes added on demand.
get_checkedNodesnoneArrayReturns an array of the checked nodes when CheckBoxes="True"
get_draggingClueElementnoneDIVReturns the div element of the dragged node (during OnClientNodeDragging event handler)
set_singleExpandPathBooleannoneAllows only a single node to be expanded when set to true. On expanding a second node, the first one returns to its initial state (that is collapsed).
get_singleExpandPathnoneBooleanReturns true if the singleExpandPath property is enabled, false otherwise.
addNodesToRadTreeNode, Array of RadTreeNode objectsnoneAdds child Nodes to the Nodes collection of a Node (defined as first parameter)
checkAllNodesnonenoneChecks all Nodes at all levels of the tree
uncheckAllNodesnonenoneUn-checks all Nodes at all levels of the tree
checkNodesArray of RadTreeNode objects or RadTreeNodeCollectionnoneChecks the defined in the parameter Nodes
uncheckNodesArray of RadTreeNode objects or RadTreeNodeCollectionnoneUn-checks the defined in the parameter Nodes
selectAllNodesnonenoneSelects all Nodes at all levels of the tree
selectNodesArray of RadTreeNode objects or RadTreeNodeCollectionnoneSelects the defined in the parameter Nodes
unselectNodesArray of RadTreeNode objects or RadTreeNodeCollectionnoneUn-selects the defined in the parameter Nodes
bulkUpdateWithfunctionnoneBulks update operations over the current TreeView instance, executed in the passed function. bulkUpdateWith is one of the many performance optimizations made on RadTreeView and basically allows the users to perform multiple changes in the TreeView instance (add/remove/expand/collapse/select/unselect/check/uncheck nodes and so on) as a single update over the inner state representation. (see Example 14)

Example 1: Demonstrates the usage of the trackChanges method

JavaScript
function AddNode() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    tree.trackChanges();
    var node = new Telerik.Web.UI.RadTreeNode();
    tree.get_nodes().add(node);
    node.set_text("New Node");
    tree.commitChanges();
}		

When adding a node client-side, the node should be created, added to the nodes collection and then has its properties customized.

Example 2: Demonstrates the usage of the findNodeByText method

JavaScript
function FindNode() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var node = tree.findNodeByText("Child RadTreeNode 1");
    node.select();
}		

Example 3: Demonstrates the usage of the findNodeByValue method

JavaScript
function FindNode() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var node = tree.findNodeByValue("3");   
    node.select();
}		

Example 4: Demonstrates the usage of the findNodeByAttribute method

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

Example 5: Demonstrates the usage of the get_selectedNodes method

JavaScript
function GetSelectedNodes() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var nodes = tree.get_selectedNodes();
    for (var i = 0; i < nodes.length; i++) {
        alert(nodes[i].get_text());
    }
}		

Example 6: Demonstrates the usage of the unselectAllNodes method

JavaScript
function UnSelectAllNodes() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    tree.unselectAllNodes();
}			

Example 7: Demonstrates the usage of the get_nodes method

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

Example 8: Demonstrates the usage of the get_allNodes method

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

Example 9: Demonstrates the usage of the get_selectedNode method

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

Example 10: Demonstrates the usage of the get_id method

JavaScript
function GetID() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    alert(tree.get_id());
}		

Example 11: Demonstrates the usage of the get_element method

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

Example 12: Demonstrates the usage of the get_element method

JavaScript
function disableTreeView() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    if (tree.get_enabled()) {
        tree.set_enabled(false);
    }
    else {
        tree.set_enabled(true);
    }
}		

 

Example 13: Demonstrates the usage of the set_loadingMessage method

JavaScript
function pageLoad() {
    var tree = $find("<%= RadTreeView1.ClientID %>");
    tree.set_loadingMessage("loading");
}	

 

Example 14: Demonstrates the usage of the bulkUpdateWith method

JavaScript
function updateTreeView(tree)
{
    tree.bulkUpdateWith(func);
}

function func()
{
    var tree = $find("RadTreeView1");
    var nodes = tree.get_nodes();
    var nodesCount = nodes.get_count();
    
    for (var i = 0; i < nodesCount; i++)
    {
        var node = nodes.getNode(i);
        // add a childNode
        var childNode = new Telerik.Web.UI.RadTreeNode();
        childNode.set_text("childNode");
        node.get_nodes().add(childNode);
        // perform other changes on the node
        node.set_expanded(true);
        node.set_checked(true);
        node.set_selected(true);
    }
}
Not finding the help you need?
Contact Support