toggleSelectedNode with parents.

2 posts, 0 answers
  1. Per Holmqvist
    Per Holmqvist avatar
    194 posts
    Member since:
    Nov 2002

    Posted 20 Aug 2009 Link to this post

    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? ;)
  2. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 20 Aug 2009 Link to this post

    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.
Back to Top