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

Item counts in group headers with multiple groups

3 Answers 248 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Charles asked on 25 Sep 2013, 05:54 PM
I have a grid with two groupings - First group by leadtype, and then for each leadtype, group by Employee. I am able to get the groupings to work fine but can't figure out how to get the item count (lead count) to show correctly in the main group (lead type) header and each of the sub group (employee) header. I have studied the examples and documentation tried a number of different groupbyexpressions but I either get {0}  for the count or the groupings get all messed up.

Any help is appreciated!
Thanks

Charles

Here is the grid definition I have so far:
<telerik:RadGrid ID="rgLeads" ShowGroupPanel="false" AutoGenerateColumns="false" AllowSorting="true"
        ShowFooter="False" runat="server" GridLines="None"
    AllowPaging="true" PageSize="15" Width="100%" >
 
    <MasterTableView DataSourceID="sqldsLeads" ShowGroupFooter="false" CommandItemDisplay="Top" EditMode="InPlace" PagerStyle-PageSizes="15,25,50,100,250,500,1000">
        <PagerStyle AlwaysVisible="true"/>
        <CommandItemSettings ShowExportToExcelButton="true" ShowExportToCsvButton="true" ShowExportToWordButton="true" ShowAddNewRecordButton="false">
        </CommandItemSettings>
        <%--<GroupHeaderTemplate>
            <asp:Label runat="server" ID="Label3" style="font-weight:bold" Text='<%# Eval("LeadType")%>' ></asp:Label>
            <asp:Label runat="server" ID="Label1" style="font-weight:bold" Text='<%# "(" + Eval("TotalCount").ToString() + " Total)" %>' ></asp:Label>
        </GroupHeaderTemplate>--%>
        <Columns>
            <telerik:GridTemplateColumn HeaderText="ID">
                <ItemTemplate>
                     <asp:label runat="server" ID="lblTicketID" Text='<%# Eval("UpTicketID") %>' ></asp:label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn>
                <ItemTemplate>
                     <asp:ImageButton runat="server" ID="imgbtnPrint" ImageUrl="images/print_16.gif" OnClick="imgbtnPrint_click" ToolTip="Print lead datasheet." />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Date" SortExpression="CreatedTDS">
                <ItemTemplate>
                     <asp:label runat="server" ID="lblDate" Text='<%# Format(Eval("CreatedTDS"),"M/d/yyyy") %>' ToolTip='<%# Format(Eval("CreatedTDS"),"t") %>' ></asp:label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
                                                         
            <telerik:GridBoundColumn DataField="LeadType" HeaderText="Type" SortExpression="LeadType" Aggregate="Count" >
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="EmployeeName" HeaderText="Employee" SortExpression="EmployeeName" >
            </telerik:GridBoundColumn>
                                                                                                                 
            <telerik:GridTemplateColumn HeaderText="Name" SortExpression="Lname">
                <ItemTemplate>
                     <asp:HyperLink runat="server" ID="hlClientHistory" NavigateUrl='<%# "ClientHistory2.aspx?clientID=" + CStr(Eval("ClientID"))%>' Text='<%# Eval("ClientName") %>' Target="_blank" ></asp:HyperLink>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Phone">
                <ItemTemplate>
                    <asp:label runat="server" ID="lblPhone" ></asp:label>
                </ItemTemplate>
                <ItemStyle Width="120px" />
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Email">
                <ItemTemplate>
                     <a href='mailto:<%# Eval("EmailAddress") %>' style="font-family: Segoe UI, Arial, Verdana; font-size: 11px; color: #777697;"><%# Eval("EmailAddress") %></a>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Address">
                <ItemTemplate>
                     <asp:label runat="server" ID="lblAddress" ></asp:label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Vehicle" SortExpression="Manufacturer">
                <ItemTemplate>
                     <asp:label runat="server" ID="lblVehicle" Text='<%# Eval("Vehicle") %>' ></asp:label>
                    <asp:LinkButton runat="server" ID="lbShowVehicle" OnClick="lbShowVehicle_click" Text='<%# Eval("Vehicle") %>' style="font-family: Segoe UI, Arial, Verdana; font-size: 11px; color: #777697;"></asp:LinkButton>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="LeadType" FieldAlias="LeadType" >
                    </telerik:GridGroupByField>
                </GroupByFields>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="LeadType" FieldAlias="LeadType" HeaderText="Lead Type" >
                    </telerik:GridGroupByField>
                    <%--<telerik:GridGroupByField FieldName="UpTicketID" FieldAlias="TicketCount" Aggregate="Count" >
                    </telerik:GridGroupByField>--%>
                </SelectFields>
            </telerik:GridGroupByExpression>
            <telerik:GridGroupByExpression>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="EmployeeName" FieldAlias="EmployeeName" >
                    </telerik:GridGroupByField>
                </GroupByFields>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="EmployeeName" FieldAlias="EmployeeName" HeaderText="Employee" >
                    </telerik:GridGroupByField>
                    <%--<telerik:GridGroupByField FieldName="UpTicketID" FieldAlias="TicketCount" Aggregate="Count"  >
                    </telerik:GridGroupByField>--%>
                </SelectFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
    </MasterTableView>
    <ExportSettings ExportOnlyData="true" IgnorePaging="true">
        <Excel Format="Biff"></Excel>
    </ExportSettings>
 
    <ClientSettings AllowDragToGroup="true">
    </ClientSettings>
    <GroupingSettings ShowUnGroupButton="true" ></GroupingSettings>
</telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 30 Sep 2013, 10:38 AM
Hello Charles,

You can refer to the following thread for the described requirement:
http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-group-by-expression-need-row-count-with-nested-radgrid.aspx

Hope this helps.

Regards,
Eyup
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.
0
Charles
Top achievements
Rank 1
answered on 30 Sep 2013, 03:15 PM
Hi Eyup,
Looping through the items in the grid works sort of, but there are problems with that approach. 1) My grid will contain thousands of items and this really slows down the page. 2) when a grouping is split between two pages, this only counts the item on the current page giving an incorrect total. and 3) we allows the user to add or remove groupings from the grid further complicating the code.

Could you please show me how to do this natively in the grid using GroupByExpressions and/or GroupHeaderTemplates? I cannot find any examples that show how to do this where there is more than one grouping. Please see the attached image to see what I am trying to do.

Thank you for your assistance.

Charles
0
Eyup
Telerik team
answered on 03 Oct 2013, 02:07 PM
Hello Charles,

You can use the following approach to achieve the requested functionality:
protected void RadGrid1_GroupsChanging(object sender, GridGroupsChangingEventArgs e)
{
    if (e.Action == GridGroupsChangingAction.Group)
    {
        if (e.Expression.SelectFields.Count < 2)
        {
            e.Expression.SelectFields.Add(new GridGroupByField
            {
                FieldName = e.Expression.GroupByFields[0].FieldName,
                FieldAlias = "LeadCount",
                HeaderText = "Lead Count",
                Aggregate = GridAggregateFunction.Count,
                HeaderValueSeparator = " ",
                FormatString = ": {0}"
            });
        }
    }
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
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
Charles
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Charles
Top achievements
Rank 1
Share this question
or