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

Nested Grouping

3 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
lupotana
Top achievements
Rank 1
lupotana asked on 12 Oct 2012, 01:33 PM
Hi,
I could try to make a nested grouping with RadGrid.
The first field to group is "Campionato" (Champion),
the second is "Gara" (Game)

I can do this work with drag &drop column (see attahced Correct.png).
but I want that this grouping is fixed when load Grid (client or server)

I can add GridGroupByField in aspx 
<telerik:RadGrid ID="gvList" runat="server" PageSize="20" AllowSorting="True" AllowPaging="True"
                   ShowGroupPanel="True" AutoGenerateColumns="False" GridLines="None">
                   <PagerStyle Mode="NumericPages"></PagerStyle>
                   <MasterTableView Width="100%" GroupLoadMode="Server" TableLayout="Fixed">
                       <GroupByExpressions>
                           <telerik:GridGroupByExpression>
                               <SelectFields>
                                   <telerik:GridGroupByField FieldAlias="CAMPIONATO" FieldName="C01_B04_CODE_FK"></telerik:GridGroupByField>
                                   <telerik:GridGroupByField FieldAlias="GARA" FieldName="C01_GARA_PK"></telerik:GridGroupByField>
                               </SelectFields>
                               <GroupByFields>
                                   <telerik:GridGroupByField FieldName="C01_B04_CODE_FK"></telerik:GridGroupByField>
                               </GroupByFields>
                           </telerik:GridGroupByExpression>
                       </GroupByExpressions>
or use che code behind
 
GridGroupByExpression expression = new GridGroupByExpression();
        GridGroupByField existing = expression.SelectFields.FindByName("C01_GARA_PK");
  
        GridGroupByField field = new GridGroupByField();
        field.FieldName = "C01_B04_CODE_FK";
        field.FieldAlias = "CAMPIONATO";
  
        GridGroupByField field = new GridGroupByField();
        field.FieldName = "C01_GARA_PK";
        field.FieldAlias = "GARA";
  
        expression.SelectFields.Add(field);
  
        gvList.MasterTableView.GroupByExpressions.Add(expression);
        gvList.Rebind();

but the result is wrong (see attached Wrong.png)

HoW do i do ?

3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 17 Oct 2012, 07:20 AM
Hello Marco,

To achieve the desired functionality you need to add two different GridGroupByExpressions. For example:
<GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <SelectFields>
                        <telerik:GridGroupByField FieldAlias="CAMPIONATO" FieldName="C01_B04_CODE_FK"></telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldName="C01_B04_CODE_FK"></telerik:GridGroupByField>
                    </GroupByFields>
                </telerik:GridGroupByExpression>
                <telerik:GridGroupByExpression>
                    <SelectFields>
                        <telerik:GridGroupByField FieldAlias="GARA" FieldName="C01_GARA_PK"></telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                       <telerik:GridGroupByField FieldAlias="GARA" FieldName="C01_GARA_PK"></telerik:GridGroupByField>
                    </GroupByFields>
                </telerik:GridGroupByExpression>
More information about grouping you could find here:
http://www.telerik.com/help/aspnet-ajax/grid-group-by-declarative-definition.html
http://www.telerik.com/help/aspnet-ajax/grid-group-by-programmatic-definition.html

I hope this helps.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Dylan
Top achievements
Rank 1
answered on 12 Nov 2013, 07:56 PM
Using the method you've described, I'm trying to create a separate GroupHeaderTemplate for each grouping level. The code below seemed like the logical thing to do, but the following binding error was thrown on the second GroupHeaderTemplate: 

'System.Data.DataRowView' does not contain a property with the name 'C01_GARA_PK'.

<GroupHeaderTemplate>
    <asp:Label ID="lblGroupName" runat="server" Text='<%# Eval("C01_B04_CODE_FK") %>' />
</GroupHeaderTemplate>
<GroupHeaderTemplate>
    <asp:Label ID="lblMonth" runat="server" Text='<%# Eval("C01_GARA_PK") %>' />
</GroupHeaderTemplate>

To take it a step further, what if I wanted to specify a GroupHeaderTemplate/GroupFooterTemplate for the inside group only... How can I achieve customizable layouts between the independent headers/footers? It seems as though, the headers/footers are only meant to be used in a nonhierarchical scenario.
0
Marin
Telerik team
answered on 15 Nov 2013, 11:38 AM
Hello,

 The grid supports only a single GroupHeader/Footer Template that would be applied on all levels.
Since the template comprises lots of items it does not hold value of a single field such as:  <%# Eval("C01_B04_CODE_FK") %>'. In the header/footer templates you only have access to the aggregated values (through the AggregateValues collection) in case you have defined aggregates in the grouping.
More information can be found in the following help topic:
http://www.telerik.com/help/aspnet-ajax/grid-group-header-footer-templates.html

Regards,
Marin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
lupotana
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Dylan
Top achievements
Rank 1
Marin
Telerik team
Share this question
or