如何使用Kendo UI mvc扩展显示网格页脚值

How to display grid footer values using Kendo UI mvc extensions

本文关键字:网格 显示 扩展 何使用 Kendo UI mvc      更新时间:2024-04-30

剑道文档非常可怕,它们中的大多数都是面向纯javascript实现的。

我正在尝试显示网格页脚值,我把一些样本拼凑在一起,得到了以下内容,但我的页脚值显示为空白。

我看到请求中返回的值是返回的JSON的一部分,但在模板中访问它们时,这些值似乎为null。

我已经尝试过(Sum)(Sum.Value),尽管Sum.Value返回一个错误,说sum属性为null。

@{ var g = Html.Kendo().Grid<OrderViewModel>()
  .Name("Orders")
  .Columns(c =>
  {
      c.Bound(p => p.OrderID).Title("ID").Width(80);
      c.Bound(p => p.OrderDate).Width(105).Format("{0:d}").Title("Date");
      c.Bound(p => p.Name).Title("Name").FooterTemplate(i => i.Count);
      c.Bound(p => p.Company).Title("Company");
      c.Bound(p => p.Email);
      c.Bound(p => p.Phone).Title("Phone");
      c.Bound(p => p.Total).Width(100).Format("{0:c}").FooterTemplate(@<text>@item.Sum</text>);
      c.Bound(p => p.Approved).Width(100);
      c.Command(command => { command.Edit().Text("&#x200b;").UpdateText("&#x200b;").CancelText("&#x200b;"); }).Width(154);
  })
    .DataSource(d => d
        .Ajax()
        .Aggregates(aggregates => {
            aggregates.Add(a => a.Total).Sum();
            aggregates.Add(a => a.Name).Count();
        })
        .Read(a => a.Action("GetOrders", "Orders"))
        .Update(a => a.Action("UpdateOrder", "Orders"))
        .PageSize(10)
        .Sort(sort => sort.Add("OrderDate").Descending())
        .Model(model => model.Id(p => p.ID))
        )
    .Pageable()
    .Sortable()
    .Filterable()
    .Editable(e => e.Mode(GridEditMode.InLine))
    .Resizable(r => r.Columns(true));
    @g
} 

你知道我缺少什么吗?

聚合部分来自它们的样本,但同一个样本并不需要显示模板本身。

我也试过数数,但没有成功。请参阅我的绑定列(Name)(Total)

我敢肯定,如果您在数据源中使用Ajax绑定而不是服务器绑定,那么您必须使用客户端模板。

例如。

更换

c.Bound(p => p.Total).Width(100).Format("{0:c}").FooterTemplate(@<text>@item.Sum</text>);

带有

c.Bound(p => p.Total).Width(100).Format("{0:c}").ClientFooterTemplate("#=sum#")

希望能有所帮助。。。我发现Docs也有同样的问题。