问题
I am trying to add a sum aggregate in the HTML helper for the grid, but am not sure how to add it for the Total field in this example. This is my simple example:
@(Html.Kendo().Grid(Model).Name("Grid")
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.Columns(columns =>
{
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.Email);
columns.Bound(p => p.Total).ClientFooterTemplate("Sum: $#= sum #");
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Users_Read", "Home"))
))
回答1:
You are not defining the aggregate
in the DataSource
:
@(Html.Kendo().Grid(Model).Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.Email);
columns.Bound(p => p.Total).FooterTemplate("Sum: #= sum #");
})
.DataSource(dataSource =>
dataSource.Ajax()
.Read(read => read.Action("Users_Read", "Home"));
.Aggregates(aggregates => { aggregates.Add(p => p.Total).Sum(); } )
.ServerOperation(false)
))
回答2:
This should work.FooterTemplate(@<text>Total Count: @item.Sum</text>)
来源:https://stackoverflow.com/questions/13536668/kendoui-adding-grid-aggregates-with-html-helper-in-mvc4