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

[Solved] toggleSelectedNode with parents.

1 Answer 85 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Per Holmqvist
Top achievements
Rank 2
Per Holmqvist asked on 20 Aug 2009, 01:19 PM
I have noticed a bug or atleast an extended need on the cklient side script
          
 function toggleSelectedNode()  
        {  
           var treeView = $find("<%=RadTreeView1.ClientID%>")  
           var selectedNode = treeView.get_selectedNode();  
           selectedNode.toggle();  
             
        } 

If you try the page http://localhost:8301/radcontrols_aspnetajax/treeview/examples/programming/clientsideapi/defaultcs.aspx
and click on the Search Folders icon to open that item. select the large mail and then click on the icon to close the Searchfolder item.
Then click on the button "Toggle selected node" the Search folder don't get toggled...

It would be great with an extended version like toogleSelectedodeWithParents or something.
Anybody that knows a script that does the trick? ;)

1 Answer, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 20 Aug 2009, 03:19 PM
First just a quick note that the URL you provided is from your local copy of the demo, not the online one. Here's the link to the demo on telerik.com:
http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/clientsideapi/defaultcs.aspx

The functionality you want can be achieved by getting the parent of the selected node and then toggling that.

 function toggleSelectedNode()   
        {   
           var treeView = $find("<%=RadTreeView1.ClientID%>")   
           var selectedNode = treeView.get_selectedNode();  
           var selectedParentNode = selectedNode.get_parent(); 
           selectedParentNode.toggle(); 
           selectedNode.toggle();   
              
        }  

Should do the trick. I'm not 100% sure if this will break when toggle() gets executed on the selectedParentNode when there is no parent, however my preliminary tests (not with toggling, just the child/parent behavior) did nothing when it was a root node and worked fine when I had a child node selected.
Tags
TreeView
Asked by
Per Holmqvist
Top achievements
Rank 2
Answers by
Schlurk
Top achievements
Rank 2
Share this question
or