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.
http://jsfiddle.net/UHzcw/44/
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?
@(Html.Kendo().Grid<ReportListViewModel>()
.Name("ReportList")
.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 })
.PageSize(500))
.ToolBar(toolbar =>
{
toolbar.Template(@<text>
<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>
</span>
</div>
</text>);
})
.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.Input(true).Numeric(false);
p.PageSizes(new int[] { 250, 500, 1000, 2500, 5000 });
})
.Filterable(filterable =>
filterable.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.DoesNotContain("Does not contain")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
.StartsWith("Starts with")
.EndsWith("Ends with ")
)
)
)
.AutoBind(false)
.ColumnMenu()
.Events(e => e.DataBound("OnDataBoundReportList"))
.Scrollable(builder => builder.Enabled(true).Height("500px"))
.Reorderable(r => r.Columns(true))
)
http://jsfiddle.net/UHzcw/44/
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?
@(Html.Kendo().Grid<ReportListViewModel>()
.Name("ReportList")
.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 })
.PageSize(500))
.ToolBar(toolbar =>
{
toolbar.Template(@<text>
<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>
</span>
</div>
</text>);
})
.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.Input(true).Numeric(false);
p.PageSizes(new int[] { 250, 500, 1000, 2500, 5000 });
})
.Filterable(filterable =>
filterable.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.DoesNotContain("Does not contain")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
.StartsWith("Starts with")
.EndsWith("Ends with ")
)
)
)
.AutoBind(false)
.ColumnMenu()
.Events(e => e.DataBound("OnDataBoundReportList"))
.Scrollable(builder => builder.Enabled(true).Height("500px"))
.Reorderable(r => r.Columns(true))
)