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

时间:2013-12-09 01:36:55

标签: javascript asp.net-mvc kendo-ui kendo-grid

剑道文档非常可怕,其中大多数都面向纯粹的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)

1 个答案:

答案 0 :(得分:0)

我非常确定如果您在数据源中使用Ajax Binding而不是Server Binding,那么您必须使用客户端模板。

例如。

替换

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中发现了同样的问题。