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

Nested Grouping Header Totals

3 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Timothy Kruszewski
Top achievements
Rank 1
Timothy Kruszewski asked on 13 Oct 2010, 10:17 PM

I'm trying to add totals to the headers of my grouping columns but can't figure out how to do it.  As you can see from the image I attached I need to see the total ticket count for each region before or after it has been expanded and I need to same logic applied to the second grouping by client as well.  Is this something that can be done or do I need to use detail grids here?

<telerik:RadGrid ID="rg1" runat="server" DataSourceID="dsPriority1" Skin="Web20"
                                                    AllowAutomaticUpdates="false" AllowAutomaticDeletes="true" AutoGenerateColumns="false"
                                                    AllowSorting="true" AllowPaging="false" ShowFooter="true" PageSize="50" PagerStyle-Position="TopAndBottom">
                                                    <MasterTableView ShowGroupFooter="true" GroupsDefaultExpanded="false" HeaderStyle-BackColor="#7FA5D7"
                                                        ItemStyle-BackColor="#B0C4DE" AlternatingItemStyle-BackColor="White" FooterStyle-Font-Bold="true">
                                                        <Columns>
                                                            <telerik:GridBoundColumn HeaderText="Region" DataField="Region">
                                                            </telerik:GridBoundColumn>
                                                            <telerik:GridBoundColumn HeaderText="Client" DataField="ClientName">
                                                            </telerik:GridBoundColumn>
                                                            <telerik:GridBoundColumn HeaderText="Ticket #" DataField="TicketNumber" Aggregate="Count">
                                                            </telerik:GridBoundColumn>
                                                        </Columns>
                                                        <GroupByExpressions>
                                                            <telerik:GridGroupByExpression>
                                                                <GroupByFields>
                                                                    <telerik:GridGroupByField FieldName="Region" />
                                                                </GroupByFields>
                                                                <SelectFields>
                                                                    <telerik:GridGroupByField FieldName="Region" HeaderText="Region" SortOrder="Ascending" />
                                                                </SelectFields>
                                                            </telerik:GridGroupByExpression>
                                                        </GroupByExpressions>
                                                        <GroupByExpressions>
                                                            <telerik:GridGroupByExpression>
                                                                <GroupByFields>
                                                                    <telerik:GridGroupByField FieldName="ClientName" />
                                                                </GroupByFields>
                                                                <SelectFields>
                                                                    <telerik:GridGroupByField FieldName="ClientName" HeaderText="Client" SortOrder="Ascending" />
                                                                </SelectFields>
                                                            </telerik:GridGroupByExpression>
                                                        </GroupByExpressions>
                                                    </MasterTableView>
                                                </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 14 Oct 2010, 12:37 AM
I've figured out how to get the total count when the region is not expanded as show in the attached image.  Now I just need to get the count for the clients.

GridGroupByExpression expression1 = GridGroupByExpression.Parse("Region, count(TicketCount) TicketCount [Total Ticket Count] Group By Region");
            CustomizeExpression(expression1);
  
            rg1.MasterTableView.GroupByExpressions.Add(expression1);
            rg1.DataBind();
  
private void CustomizeExpression(GridGroupByExpression expression)
    {
        //avoid adding the total field twice
        GridGroupByField existing = expression.SelectFields.FindByName("TicketCount");
        if (existing == null) //field is not present
        {
            //Construct and add a new aggregate field 
            GridGroupByField field = new GridGroupByField();
            field.FieldName = "TicketCount";
            field.FieldAlias = "SubTotal";
            field.Aggregate = GridAggregateFunction.Sum;
  
            expression.SelectFields.Add(field);
        }
        else //field is present then set a format string
        {
            //existing.FormatString = "{0:C}";
        }
    }


<telerik:RadGrid ID="rg1" runat="server" DataSourceID="dsPriority1" Skin="Web20"
                                                    AllowAutomaticUpdates="false" AllowAutomaticDeletes="true" AutoGenerateColumns="false"
                                                    AllowSorting="true" AllowPaging="false" ShowFooter="true" ShowGroupPanel="true"
                                                    ShowGroupHeader="true" PageSize="50" PagerStyle-Position="TopAndBottom" OnItemDataBound="rg1_ItemDataBound">
                                                    <MasterTableView ShowGroupFooter="true" GroupsDefaultExpanded="false" HeaderStyle-BackColor="#7FA5D7"
                                                        ItemStyle-BackColor="#B0C4DE" AlternatingItemStyle-BackColor="White" FooterStyle-Font-Bold="true">
                                                        <Columns>
                                                            <telerik:GridBoundColumn HeaderText="Region" DataField="Region">
                                                            </telerik:GridBoundColumn>
                                                            <telerik:GridBoundColumn HeaderText="Client" DataField="ClientName">
                                                            </telerik:GridBoundColumn>
                                                            <telerik:GridTemplateColumn HeaderText="Ticket #" UniqueName="TicketNumber" Aggregate="Count"
                                                                DataField="TicketNumber">
                                                                <ItemTemplate>
                                                                    <asp:HyperLink ID="hlTicket" runat="server" Text='<%# Bind("TicketNumber") %>'></asp:HyperLink>
                                                                </ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridBoundColumn HeaderText="TicketID" DataField="TicketID" Visible="false">
                                                            </telerik:GridBoundColumn>
                                                        </Columns>
                                                        <GroupByExpressions>
                                                            <telerik:GridGroupByExpression>
                                                                <GroupByFields>
                                                                    <telerik:GridGroupByField FieldName="Region" />
                                                                </GroupByFields>
                                                                <SelectFields>
                                                                    <telerik:GridGroupByField FieldName="Region" HeaderText="Region" SortOrder="Ascending" />
                                                                </SelectFields>
                                                            </telerik:GridGroupByExpression>
                                                        </GroupByExpressions>
                                                        <GroupByExpressions>
                                                            <telerik:GridGroupByExpression>
                                                                <GroupByFields>
                                                                    <telerik:GridGroupByField FieldName="ClientName" />
                                                                </GroupByFields>
                                                                <SelectFields>
                                                                    <telerik:GridGroupByField FieldName="ClientName" HeaderText="Client" SortOrder="Ascending" />
                                                                </SelectFields>
                                                            </telerik:GridGroupByExpression>
                                                        </GroupByExpressions>
                                                    </MasterTableView>
                                                </telerik:RadGrid>
0
Accepted
Daniel
Telerik team
answered on 19 Oct 2010, 01:52 PM
Hello Timothy,

Please download the attached project and let me know whether the demonstrated approach is suitable for your scenario.

Regards,
Daniel
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
Timothy Kruszewski
Top achievements
Rank 1
answered on 19 Oct 2010, 04:24 PM
Thank you, that was almost to simple.
Tags
Grid
Asked by
Timothy Kruszewski
Top achievements
Rank 1
Answers by
Timothy Kruszewski
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or