Disable Collapse in TreeView

7 posts, 0 answers
  1. piro
    piro avatar
    6 posts
    Member since:
    Mar 2008

    Posted 25 Dec 2008 Link to this post

    I want to disable collapse property went click a node on tree view. How can't i do it?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Dec 2008 Link to this post

    Hi,

    Try the following code snippet to achieve the desired scenario.


    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" OnClientNodeCollapsing="OnClientNodeCollapsing"      runat="server"  > 
              

    JS:
    <script type="text/javascript"
    function OnClientNodeCollapsing(sender, eventArgs) 
    var node = eventArgs.get_node(); 
     eventArgs.set_cancel(true); 
    </script> 



    Shinu
  3. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 22 Mar 2009 Link to this post

    This is very useful code.  How can we modify it to disable collapse for only the top (first) node?
  4. Yana
    Admin
    Yana avatar
    4985 posts

    Posted 23 Mar 2009 Link to this post

    Hello John,

    Please modify the js function like this:

    <script type="text/javascript">    
    function OnClientNodeCollapsing(sender, eventArgs)    
    {    
       var node = eventArgs.get_node();    
       if(node.get_level() == 0)  
         eventArgs.set_cancel(true);    
    }    
    </script>    
     

    Kind regards,
    Yana
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 23 Mar 2009 Link to this post

    Yana,
    It works great, thank you. 

    This technique could help others who posted questions about how to change font from subdued to normal when a node is disabled.  You can enable a node to achieve normal font display, then use this code to simulate a disabled node.

    Steve
  6. Edward
    Edward avatar
    1 posts
    Member since:
    Aug 2012

    Posted 29 Jul 2009 Link to this post

    Hi,

    In my current project I have the need to show the root node, but make it so that it can't be collapsed.  This fix gets my partially there, but usability testing shows that it would be better to have a way of not showing the collapse icon at all. Is there any way to hide the [-] (minus sign in my case), so that users don't get confused?  It would also give me additional real estate on the left side.

    So this:

    [-] Root Node
    .......|-- [+] Next Level

    would become:

    Root Node
    ...|-- [+] Next Level


    I have seen the posts that suggest change the display style to 'none' on the toggle element.  I sort of see that as a hack and was hoping there was a better, cleaner way of geeting the result above. That fix also doesn't gain the space back from where the toggle and line are.


    Thanks,
    Ed R.
  7. Yana
    Admin
    Yana avatar
    4985 posts

    Posted 30 Jul 2009 Link to this post

    Hi Edward,

    Unfortunately setting display to "none" to the toggle element is the only way to remove it.

    Greetings,
    Yana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top