This is a migrated thread and some comments may be shown as answers.

How to collapse "other" nodes

1 Answer 49 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ed Staffin
Top achievements
Rank 1
Ed Staffin asked on 08 Dec 2011, 12:47 PM
Hi,
Since there is no documented "IsDecendantOf" function on the client side, I was wondering if anyone has figured out how to collapse all other branches of the tree when expanding a particular node in javascript.
For example, if I have a tree as follows
    A
        B
        C
            D
    E
        F
            G
I want that when they expand C, E collapses and if they expand F I would want A to collapse.
Basically, if they expand a branch, I want all OTHER branches to collapse.
If anyone has done this and is willing to share how they did it I would be much obliged.
Thanks ... Ed

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 08 Dec 2011, 03:40 PM
Hello Ed Staffin,

Here is a sample funcion you can attach to the OnClientNodeExpanding event:

function clientNodeExpanding(sender, args){
    var nodeToBeExpanded = args.get_node();
    var parent = nodeToBeExpanded.get_parent();
    for (var i = 0; i < parent.get_nodes().get_count(); i++) {
        parent.get_nodes().getNode(i).collapse();
    }
    for (var i = 0; i < nodeToBeExpanded.get_nodes().get_count(); i++) {
        nodeToBeExpanded.get_nodes().getNode(i).collapse();
    }  
}
All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeView
Asked by
Ed Staffin
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or