Grouping: Expand One Group Only

3 posts, 1 answers
  1. Chris May IT Team Lead
    Chris May IT Team Lead avatar
    31 posts
    Member since:
    Nov 2009

    Posted 21 Jul 2010 Link to this post


    I have a RadGrid with three groups.  I would like to always have one and only one group expanded at a time.  I have successfully configured the grid to have the first group by doing this in the ItemDataBound event:
    If TypeOf e.Item Is GridGroupHeaderItem Then
        Dim item As GridGroupHeaderItem = e.Item
        If item.GroupIndex = "0" Then
        item.Expanded = True
        End If
    End If

    I tried this code to handle expanding only the "clicked on" header item, but it does not work:

    Private Sub rgvReportGrid_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvReportGrid.ItemCommand
        If e.CommandName = RadGrid.ExpandCollapseCommandName Then
            Dim item As GridGroupHeaderItem = e.Item
            Dim groupIndex As String = item.GroupIndex.ToString
            Dim grid As RadGrid = source
            For Each gridItem As GridItem In grid.MasterTableView.Controls(0).Controls
                If TypeOf (gridItem) Is GridGroupHeaderItem Then
                    Dim groupHeaderItem As GridGroupHeaderItem = gridItem
                    If groupHeaderItem.GroupIndex.ToString = groupIndex Then
                        groupHeaderItem.Expanded = True
                        groupHeaderItem.Expanded = False
                    End If
                End If
        End If
    End Sub

    Even though I'm setting the .Expanded attribute to True (I observe that one item gets hit during debugging), all groups end up collapsed.

    I know I can use GroupLoadMode="Client" and try to handle things in Javascript, but I'm not really sure where to begin with that.  I guess I'd prefer to not round-trip to the server, but I'll take any code that works at this point. 

    Thank you!
  2. Answer
    Tsvetina avatar
    1862 posts

    Posted 27 Jul 2010 Link to this post

    Hi Patrick,

    In order to achieve that functionality, you can add some custom logic to the solution presented in this help topic on collapsing all items when grouping. The only major difference is that you need to have one item  expanded. I prepared a sample project demonstrating how you can achieve that.

    I implemented this server-side, as doing it client-side would require a lot of custom logic.

    Additionally, as you have a support ticket opened on the same subject, please, post there if you need further assistance on that matter.

    Kind regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
  4. Chris May IT Team Lead
    Chris May IT Team Lead avatar
    31 posts
    Member since:
    Nov 2009

    Posted 03 Aug 2010 Link to this post


    This worked great, thank you!  The mistake I was making was in trying to do the expand/collapse operation in the ItemCommand event handler, rather than in the PreRender event.

Back to Top