KendoUI: Adding Grid Aggregates with HTML Helper i

2019-05-31 05:49发布

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"))

      ))

标签: kendo-ui
2条回答
淡お忘
2楼-- · 2019-05-31 06:06

This should work
.FooterTemplate(@<text>Total Count: @item.Sum</text>)

查看更多
Animai°情兽
3楼-- · 2019-05-31 06:07

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) 
  ))
查看更多
登录 后发表回答