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

Aggregation on Groupable in ASP MVC Helper

1 Answer 143 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Jason asked on 09 Jun 2014, 02:47 PM
Hello,  I am trying to figure out how to create an aggregate row on a grid when you group by any column.  I have created a demo of this using the regular kendo javascript.

However, our solution uses the mvc helpers so I'll need to be able to use that but I can't figure out how to do it.  Here is our current code that we will be adding this to.  What are we missing here?  How do you add the aggregates to each column in mvc like in the javascript version?

                            .HtmlAttributes(new { @class = "cursorLink" })
                            .DataSource(ds => ds.Ajax()
                                .Aggregates( a => {
                                    a.Add(p => p.ReportName).Count();
                                    a.Add(p => p.ReportCategoryName).Count();
                                    a.Add(p => p.User_CreatedBy).Count();
                                    a.Add(p => p.CreatedDate).Count();
                                    a.Add(p => p.ReportDescription).Count();
                                .Read("ReportListData", "Reports", new { ProductName = ViewBag.SelectedProduct.ProductName })
                            .ToolBar(toolbar =>
                                       <div class="toolbar">
                                       <span class="">
                                           <a class="btn btn-small printGridButton"><i class="icon-print"></i>Print</a>
                                           <a class="btn btn-small saveGridButton" id="SaveReportList" data-mcpagename="ReportList" data-mcuserconfigsettingid="@reportListGridUserConfigId" data-mcuserconfigsettingname="ReportList" data-mcuserconfigshowpagemessage="true"><i class="icon-hdd"></i>Save View</a>
                                           <a class="btn btn-small resetGridButton" data-mcuserconfigsettingname="ReportList" data-mcuserconfigshowpagemessage="false"><i class="icon-repeat"></i>Reset View</a>
                            .Columns(c =>
                                c.Bound(f => f.ReportName).Title("Report Name").ClientTemplate("<input type='hidden' id='GridRowURL' value='" + Url.Action("ReportView") + "/#=ReportId#' />#:data.ReportName#").Width(300).ClientFooterTemplate("#=count#");
                                c.Bound(f => f.ReportCategoryName).Title("Category").Width(125).ClientFooterTemplate("#=count#");
                                c.Bound(f => f.User_CreatedBy).Title("Created By").Width(150).ClientFooterTemplate("#=count#");
                                c.Bound(f => f.CreatedDate).Title("Date Created").Width(120).Format("{0:d}").HtmlAttributes(new { @class = "kendoGridDate" }).ClientFooterTemplate("#=count#");
                                c.Bound(f => f.ReportDescription).Title("Description").ClientFooterTemplate("#=count#");
                                //c.Template(f => { }).ClientTemplate("#if (data.ReportSubscriptionId > 0) {# <a class='btn btn-mini' href='javascript:void(0)' onclick='updateReportSubscription(#=ReportSubscriptionId#, \"#=ReportId#\")'><i class=\"icon-pencil\"></i>Edit</a> #} else {# <a class='btn btn-mini' href='javascript:void(0)' onclick='addReportSubscription(\"#=ReportId#\")'><i class=\"icon-plus\"></i>Add</a> #}#").Title("Subscribe").HtmlAttributes(new { @class = "mc_reportSubscriptionCell" }).Width(90);
                            .Sortable(s => s.SortMode(GridSortMode.MultipleColumn))
                            .Groupable(g =>
                                g.Messages(m =>
                                    m.Empty("Drag Column Header Here to Group");
                            .Pageable(p =>
                                p.PageSizes(new int[] { 250, 500, 1000, 2500, 5000 });
                            .Filterable(filterable =>
                                filterable.Operators(operators => operators
                                    .ForString(str => str.Clear()
                                        .DoesNotContain("Does not contain")
                                        .IsEqualTo("Is equal to")
                                        .IsNotEqualTo("Is not equal to")
                                        .StartsWith("Starts with")
                                        .EndsWith("Ends with ")                                
                            .Events(e => e.DataBound("OnDataBoundReportList"))
                            .Scrollable(builder => builder.Enabled(true).Height("500px"))
                            .Reorderable(r => r.Columns(true))

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 11 Jun 2014, 01:04 PM
Hello Jason,

With the MVC wrapper you should basically:
  1. Set the aggregates to the dataSource with the Aggregates method as you are currently doing and as demonstrated in the demos.
  2. Use the column ClientFooterTemplate and ClientGroupFooterTemplate methods to set the column footer and group footer templates e.g.
    c.Bound(f => f.ReportName)
        .ClientFooterTemplate("Total Count: #=count#")
        .ClientGroupFooterTemplate("Count: #=count#");

Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question