如果我創建一個隱藏列,在這種情況下爲BirthDateMonth並從數據集創建它,如果我還在另一個字段上添加組聚合,那麼它將打破JS錯誤「sum not定義爲「。具有隱藏列和聚合的Kendo UI網格
var grid = $("#grid").kendoGrid({
dataSource: {
data: createRandomData(10),
schema: {
model: {
fields: {
FirstName: { type: "string" },
LastName: { type: "string" },
City: { type: "string" },
Title: { type: "string" },
BirthDate: { type: "date" },
//BirthDateMonth: { type: "date" },
Age: { type: "number" }
},
},
parse: function (data) {
$.each(data, function (idx, item) {
if (item.BirthDate)
{
item.BirthDateMonth = new Date(item.BirthDate.getTime());
item.BirthDateMonth.setDate(1);
}
});
return data;
}
},
pageSize: 10,
aggregate: [
{field: "Age", aggregate: "sum"}
]
},
height: 500,
scrollable: true,
groupable: true,
columns: [
{
field: "FirstName",
title: "First Name"
},
{
field: "LastName",
title: "Last Name"
},
{
field: "City",
},
{
field: "Title"
},
{
field: "BirthDate",
title: "Birth Date",
template: '#= kendo.toString(BirthDate,"MM/dd/yyyy") #'
},
{
field: "BirthDateMonth",
title: "Birth Month",
template: '#= kendo.toString(BirthDateMonth,"MM/yyyy") #',
hidden: true
},
{
field: "Age",
aggregates: ["sum"],
footerTemplate: "Sum: #=sum#",
groupFooterTemplate: "Sum: #=sum#"
}
]
}).data("kendoGrid");
grid.dataSource.group([{field: "BirthDateMonth"}]);
JSFiddle,任何想法讚賞。我試圖向模式添加隱藏列字段,但沒有效果。
是的,謝謝。 – Stuart