More in this section

Forums / Developing with Sitefinity / SitePanelbar: Preventing Child items from collapsing when using Page Groups

SitePanelbar: Preventing Child items from collapsing when using Page Groups

2 posts, 0 answered
  1. mdw_cubed
    mdw_cubed avatar
    5 posts
    Registered:
    29 Mar 2007
    29 May 2009
    Link to this post
    Hi,

    I've been searching for forums for a way to prevent child items of a Page Group from collasping.  I am using the SitePanelbar to show part of the sitemap in the sidebar of one of my pages.

    I found how to ensure the SitePanelbar starts fully expanded and how to turn off the URL redirect for the Page Group item quite quickly, but the bit of functionality that elluded me was preventing the child items from collapsing.

    So, after taking a look at this post I decided to have a go myself at some code modification myself.

    The result does exactly what I wanted and its was pretty simple to implement.  Should anyone else want to do something similar, this is how I did it.

    I modified ~/Sitefinity/UserControls/Navigation35/SitePanelbar.ascx.cs control as follows:

    1. Defined a bool in the Data Fields section to hold the state of the property

    /// <summary> 
    /// Holds a boolean value, indicating if the <see cref="RadPanelbarItem"/> should allow  
    /// a group page's child items to collapse or not. If it is set to true, the panelbar item will not 
    /// collapse its child items. 
    /// </summary> 
    private bool preventCollapseForGroupPages = false

    2. Created a property which looking at the attributes of HideUrlForGroupPages I hope would appear on the property page under Behavior for the SitePanelbar and indeed it did! :)

    /// <summary> 
    /// Gets or sets a value indicating whether the RadPanelItems representing group 
    /// pages should allow collapse of their child pages. 
    /// </summary> 
    /// <remarks> 
    /// By default every group pages in the RadPanelbar expand and hide their children and disabling collapse for 
    /// a group page will mean the children nodes are always visible.  
    /// </remarks> 
    [Browsable(true)] 
    [Category("Behavior")] 
    [DefaultValue(false)] 
    public bool PreventCollapseForGroupPages  
        get 
        { 
            return this.preventCollapseForGroupPages; 
        } 
        set 
        { 
            this.preventCollapseForGroupPages = value; 
        } 

    3. Modified the code in RadPanelbar1_ItemDataBound to apply the functionality.

    public void RadPanelbar1_ItemDataBound(object sender, RadPanelBarEventArgs e) 
        if (this.hideUrlForGroupPages) 
        { 
            CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode; 
            if (node != null && node.PageType == CmsPageType.Group) 
            { 
                e.Item.NavigateUrl = ""
            } 
        } 
     
        /// Apply the PreventCollapseForGroupPages property
        if (this.preventCollapseForGroupPages) 
        { 
            CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode; 
            if (node != null && node.PageType == CmsPageType.Group) 
                e.Item.PreventCollapse = true
        }    
     

    In testing against different browsers, it works fine for FireFox 3, IE8/7/6 and Opera 9.  Both Chrome and Safari for some reason collapse the bottom child node and then show it again the first time the Page Group node is clicked.  After that first click Chrome and Safari work fine.  (I think I'll live with that for now ;))

    I'm really impressed with Sitefinity's feature and extensibility.

    I hope others find this helpful.

    Cheers
    Mark

  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    01 Jun 2009
    Link to this post
    Hello mdw_cubed,

    Thank you for sharing your solution with the community. We really appreciate that and it makes us work even harder to deliver a world class CMS. I have notified our front-end team to take a look at the Safari & Chrome issue so we'll let you know what we find out.

    I have updated your Telerik points as a token of our appreciation.

    Regards,
    Ivan
    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.
2 posts, 0 answered