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

[Solved] SingleExpandPath and OnClientNodeCollapsed

1 Answer 69 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Cory Isakson
Top achievements
Rank 1
Cory Isakson asked on 07 Apr 2008, 07:04 PM
I am trying to use SingleExpandPath and OnClientNodeCollapsed on a Prometheus TreeView.  When a node opens the OnClientNodeCollapsed is not firing on the node that is auto closed.  Is there a way to have the SingleExpandPath functionality fire OnClientNodeCollapsed when it automatically closes a node?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 08 Apr 2008, 02:15 PM
Hello Cory Isakson,

You are right - this is a problem in the treeview.
We will do our best to fix it for the official release next week.

In the meantime you can use the following workaround:

<telerik:RadTreeView ID="RadTreeView1"  
       OnClientNodeExpanded="onClientNodeExpanded" 
       runat="server"

<script type="text/javascript"
function onClientNodeExpanded(sender, eventArgs) 
    var node = eventArgs.get_node(); 
    //close all nodes that are not parents of the expanded node 
    collapseOtherNodes(node); 
}    
 
function collapseOtherNodes(node) 
    //this array will hold all the parents of the node and the node itself 
    var parents = new Array(); 
    parents[0] = node; 
    var i = 1; 
    var tree = node.get_treeView(); 
     
    while (node.get_parent() != tree) 
    { 
        parents[i] = node.get_parent(); 
        node = node.get_parent(); 
        i++; 
    }     
     
    for (var j = 0; j < tree.get_allNodes().length; j++) 
    { 
        if (!existNodeInArray(tree.get_allNodes()[j], parents)) 
        { 
            tree.get_allNodes()[j].collapse(); 
            //copy the necessary code for the client node collapsed 
        }              
    } 
 
//checks if node is in nodeArray, comparing by the Text of the node 
function existNodeInArray(node, nodeArray) 
    for (var i = 0; i < nodeArray.length; i++) 
    { 
        if (node.get_text() == nodeArray[i].get_text()) 
        { 
            return true
        } 
    } 
     
    return false
</script> 


I updated your Telerik Points as a small token of our gratitude.

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Cory Isakson
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or