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

Group by in RadGrid gives both sum and Count of 0

3 Answers 510 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 12 Dec 2016, 08:48 AM

I am using GroupByField in my GroupHeaderTemplate like this:

<telerik:RadGrid ID="grdBookingItems" runat="server">
    <MasterTableView DataKeyNames="ID" ShowFooter="True" ClientDataKeyNames="ID" Font-Size="9">
        <GroupHeaderTemplate>
            <table class="header-template-table" style="display: inline-block">
                <tr>
                    <td>
                        <b><%#Eval("EventName") %></b>
                        <%#Eval("ArticleName") %>
                        (<%#Eval("ID") %> items.)
                    </td>
                    <td style="border: none">
                        <%#Eval("Price") %>
                    </td>
                </tr>
            </table>
        </GroupHeaderTemplate>
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="EventName" />
                    <telerik:GridGroupByField FieldName="ArticleName" />
                    <telerik:GridGroupByField FieldName="Price" Aggregate="Sum" />
                    <telerik:GridGroupByField FieldName="ID" Aggregate="Count" />
                </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="ArticleName" />
                    <telerik:GridGroupByField FieldName="EventName" />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
        <RowIndicatorColumn Visible="False" FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="False" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn Visible="True" DataField="ID" UniqueName="colID" HeaderText="ID">
              <HeaderStyle Width="0" />
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="" UniqueName="checkCol" HeaderStyle-Width="50px">
                <HeaderTemplate>
                    <asp:CheckBox ID="chbMasterSelector" runat="server" Checked="True"
                        AutoPostBack="True" OnCheckedChanged="grdBookingItems_masterCheckChanged"
                        Text="" CssClass="sb-up-book" />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="chbSelectRow" runat="server" Checked="true" AutoPostBack="True"
                        CssClass="sb-up-book" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Move" UniqueName="colMove">
                <ItemTemplate>
                    <asp:Panel CssClass="popup-bookingcard-move-button" runat="server" ID="MoveButton" />
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Panel CssClass="popup-bookingcard-move-button" runat="server" ID="MoveAllButton" ToolTip="Move selected booking"/>
                </FooterTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="Amount" Aggregate="Sum" FooterAggregateFormatString="{0:g}" FilterControlAltText="Filter column column"
                HeaderText="Num" UniqueName="colAmount" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right">
                <HeaderStyle Width="36px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="EventName" FilterControlAltText="Filter column2 column"
                HeaderText="Activity" UniqueName="colEventName">
                <HeaderStyle Width="150px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="StartTime" DataType="System.DateTime" FilterControlAltText="Filter column3 column"
                HeaderText="Start time" UniqueName="colEventDate" HeaderStyle-Width="112px" DataFormatString="{0:d} {0:t}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="SectionName" 
                HeaderText="Resource" UniqueName="colSectionName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ArticleName" FilterControlAltText="Filter column1 column"
                HeaderText="Article" UniqueName="colArticleName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Price" FilterControlAltText="Filter column3 column" Aggregate="Sum" FooterAggregateFormatString="{0:g}"
                HeaderText="Price" UniqueName="colPrice" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="StatusText" FilterControlAltText="Filter column4 column"
                HeaderText="Status" UniqueName="colStatus" >
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Barcode" FilterControlAltText="Filter column4 column"
                HeaderText="Barcode" UniqueName="barCode" HeaderStyle-Width="72px">
            </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="NewTime" Visible="False" FilterControlAltText="Filter column4 column"
                HeaderText="Ny tid" UniqueName="newTime" HeaderStyle-Width="112px" DataFormatString="{0:d} {0:t}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Seatinformation" FilterControlAltText="Filter column1 column"
                HeaderText="Extra info" UniqueName="colSeatinformation">
            </telerik:GridBoundColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
        <BatchEditingSettings EditType="Cell"></BatchEditingSettings>
        <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowContextMenu="rowContextMenu" OnRowCreated="grdBookingItems_rowCreated" />
    </ClientSettings>
    <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>

 

expecting sum and count to become a summation and a count of the grouped items, but they become 0.

It will look like the attached screenshot.

Maybe this error has been introduced by upgrading the telerik components?

(We are now into version UI for ASP.NET AJAX R3 2016)

 

3 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 Dec 2016, 07:49 AM
Hello Ingemar,

You should follow the approach demonstrated in the following help article for displaying the aggregate values in the GroupHeaderTemplate:
Hope this helps.


Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Anders
Top achievements
Rank 1
answered on 15 Feb 2017, 12:01 PM

If I change the order of the items in <GroupByFields>, the aggregates works as before.

<telerik:GridGroupByField FieldName="EventName"/>

must come before

<telerik:GridGroupByField FieldName="ArticleName"/>

 

Is this a bug?

 

0
Konstantin Dikov
Telerik team
answered on 20 Feb 2017, 08:23 AM
Hello Ingemar,

The aggregates in the GroupHeaderTemplate should be displayed as demonstrated in the help topic from my previous post (through the AggregatesValues collection of the header item):
<asp:Label runat="server" ID="Label1" Text='<%# "Number of units: "+ (((GridGroupHeaderItem)Container).AggregatesValues["UnitsInStock"]) %>'
               Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["UnitsInStock"]) != null)%>'>

As for the order of the GroupByFields, that order should determine the group expression.


Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Anders
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Anders
Top achievements
Rank 1
Share this question
or