剑道文档非常糟糕,其中大多数都是针对纯 JavaScript 实现的。
我正在尝试显示网格页脚值,并将一些示例拼凑在一起以得出以下内容,但我的页脚值显示为空白。
我看到请求中返回的值作为返回的 JSON 的一部分,但在模板中访问它们时这些值似乎为空。
我尝试过 (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("​").UpdateText("​").CancelText("​"); }).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
}
我缺少什么想法吗?
聚合部分来自他们的示例,但相同的示例不费心显示模板本身。
我也尝试过计数,但没有成功。查看我绑定(bind)的列 (Name)
和 (Total)
。
最佳答案
我非常确定,如果您在数据源中使用 Ajax 绑定(bind)而不是服务器绑定(bind),那么您必须使用客户端模板。
例如。替换
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#")
希望有帮助... 我在文档中发现了同样的问题。
关于javascript - 如何使用 Kendo UI mvc 扩展显示网格页脚值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20461663/