有没有办法在剑道中创建聚合函数?
我试图在网格中求和,如果我使用 kendo 定义的 sum 函数,它只会将数字连接起来,就像它们是字符串一样。我的实际解决方案是从 kendo 更改 js 并将 mysum 函数放在那里。
我认为它就像一种魅力,但应该有更好的解决方案。
查看代码:
var dataSource = new kendo.data.DataSource({
pageSize: 20,
data: products,
autoSync: true,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
Category: { defaultValue: { CategoryID: 1,CategoryName:"Beverages"} },
UnitPrice: { type: "number", validation: { required: true,min: 1} }
}
}
},
aggregate: [ { field: "ProductName", aggregate: "count" },
{ field: "UnitPrice", aggregate: "mysum" }]
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 430,
toolbar: ["create"],
columns: [
{ field: "ProductName", title: "Product Name", footerTemplate: "Total Count: #=count#" },
{ field: "Category", title: "Category", width: "160px", editor: categoryDropDownEditor, template: "#=Category.CategoryName#" },
{ field: "UnitPrice", title:"Unit Price", width: "120px", footerTemplate: "Total Sum: #=mysum#" },
{ command: "destroy", title: " ", width: "90px" }],
editable: true
});
并且剑道ui增加了功能:
mysum:function(e,t,n){return (e || 0) + parseFloat(n.get(t))}