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

Grouping: Expand One Group Only

2 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Quinten
Top achievements
Rank 1
Quinten asked on 21 Jul 2010, 05:20 PM
Hello,

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
                Else
                    groupHeaderItem.Expanded = False
                End If
            End If
        Next
    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 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetina
Telerik team
answered on 27 Jul 2010, 11:54 AM
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,
Tsvetina
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
0
Quinten
Top achievements
Rank 1
answered on 03 Aug 2010, 10:18 PM
Tsvetina,

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.

Tags
Grid
Asked by
Quinten
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Quinten
Top achievements
Rank 1
Share this question
or