KendoUI: Adding Grid Aggregates with HTML Helper in MVC4

陌路散爱 提交于 2019-12-08 07:59:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!