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

Collapse group columns on second level grouping

4 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elena
Top achievements
Rank 1
Elena asked on 11 May 2011, 01:30 PM
Hello,
i have radgrid with grouping on two levels, here is the aspx code:
...
<GroupByExpressions>
                                <telerik:GridGroupByExpression>
                                    <SelectFields>
                                        <telerik:GridGroupByField FieldAlias="Proces" FieldName="Proces" HeaderText="<%$ Resources:StartRes, Lb_Proces %>">
                                        </telerik:GridGroupByField>
                                    </SelectFields>
                                    <GroupByFields>
                                        <telerik:GridGroupByField FieldName="Proces" SortOrder="Descending"></telerik:GridGroupByField>
                                    </GroupByFields>
                                </telerik:GridGroupByExpression>
                            </GroupByExpressions>
                            <GroupByExpressions>
                                <telerik:GridGroupByExpression>
                                    <SelectFields>
                                        <telerik:GridGroupByField FieldAlias="Postapka" FieldName="Postapka" HeaderText="<%$ Resources:StartRes, Lb_Predmet %>">
                                        </telerik:GridGroupByField>
                                        <telerik:GridGroupByField FieldAlias="BrPRedmet" FieldName="BrPRedmet" HeaderText="<%$ Resources:StartRes, BrPRedmet %>">
                                        </telerik:GridGroupByField>
                                        <telerik:GridGroupByField FieldAlias="DelSubjekt" FieldName="DelSubjekt" HeaderText="<%$ Resources:StartRes, Tv_DSubjekti %>">
                                        </telerik:GridGroupByField>
                                    </SelectFields>
                                    <GroupByFields>
                                        <telerik:GridGroupByField FieldName="BrPRedmet"  SortOrder="Descending"></telerik:GridGroupByField>
                                    </GroupByFields>
                                </telerik:GridGroupByExpression>
                            </GroupByExpressions>
...
On Page load i need all group columns to be collapsed, on the first and on the second level. In the code behind i have code to collapse the group columns on the first level. The problem is that i can't access the group columns on the second grouping level. With debugging i found that RadGrid1.MasterTableView.Controls[0].Controls[1].Controls are the  group columns on the second level, but i don't know how to cast them so i can set Expand attribute to false. Here is the code that i use to collapse group columns on first level: 
 
foreach (GridItem item in RadGrid1.MasterTableView.Controls[0].Controls)
                {
                    item.Expanded = false;
}

If i try to access group columns on the second level with GridItem cast 

foreach (GridItem item in RadGrid1.MasterTableView.Controls[0].Controls)
                {
                    item.Expanded = false;
                    foreach (GridItem subitem in item.Controls[1].Controls)
                    {
                        
                    }
                }

 i get the message 

Unable to cast object of type 'Telerik.Web.UI.GridTableHeaderCell' to type 'Telerik.Web.UI.GridItem'.

Please help me how to cast the group columns on the second level so i can collapse them all on Page Load, or tell me some other solution for collapsing group columns. 

Thank you and pardon my English, not that good.

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 11 May 2011, 02:03 PM
Hello Elena,

You can easily achieve this by setting the property GroupsDefaultExpanded as false. The groups will be expanded on grid load which is true by default).

aspx:
<MasterTableView DataKeyNames="EmpId" GroupsDefaultExpanded="false">
</MasterTableView>

Thanks,
Princy.
0
Elena
Top achievements
Rank 1
answered on 12 May 2011, 09:06 AM
Hello,

thank you for the solution. Now i realize that my problem is not in the collapsing of the group columns on the second level on Page load, but in the expanding all the sub group columns when i expand a group column on the first level. 
Is there a way to prevent expanding on second level, when user expands group column on first level.

Thank you,
Elena.
0
Accepted
Pavlina
Telerik team
answered on 17 May 2011, 01:28 PM
Hi Elena,

Go through the link below:
http://www.telerik.com/community/forums/aspnet-ajax/grid/rad-grid-grouping-default-collapsed.aspx

Regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Elena
Top achievements
Rank 1
answered on 21 May 2011, 01:03 PM
Hello,

thank you for the link. The solution was very simple: 
 <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" PageSize="250" GroupLoadMode="Server"
                                GroupsDefaultExpanded="false">
It is important  GroupsDefaultExpanded to be set False and  GroupLoadMode to be on the Server side.

Elena.
Tags
Grid
Asked by
Elena
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Elena
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or