Javascript 剑道ui网格创建聚合函数

Javascript 剑道ui网格创建聚合函数,javascript,kendo-ui,Javascript,Kendo Ui,有没有办法在剑道中创建聚合函数 我试图在网格中求和,如果我使用由kendo定义的sum函数,它只是将数字连接起来,就像它们是字符串一样。我的实际解决方案是更改剑道的js,并将mysum函数放在那里 这很有魅力,但我认为应该有更好的解决办法 查看代码: var dataSource = new kendo.data.DataSource({ pageSize: 20, data: products,

有没有办法在剑道中创建聚合函数

我试图在网格中求和,如果我使用由kendo定义的sum函数,它只是将数字连接起来,就像它们是字符串一样。我的实际解决方案是更改剑道的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
 });
和剑道界面增加了功能:

mysum:function(e,t,n){return (e || 0) + parseFloat(n.get(t))}

你好,我迟到了,但如果它能帮助别人的话

我曾经遇到过同样的问题,我实现了一个解决方案,可以帮助您在groupFooterTemplate中使用自定义聚合函数

链接到项目

函数myAggregate(数据){
//这里的数据是按组列出的数据列表(右侧!:-)
//在这里执行任何操作并返回结果字符串
}
var grid=$(“#grid”).kendoGrid({
...
栏目:[
{字段:“”,标题:“”,groupFooterTemplate:myAggregate
]
...
});

...
...
//jQuery在这里
//这里是kendo.all.min.js

请为视图和脚本共享您的代码。对于剑道库,我创建函数:mysum:function(e,t,n){return(e | | 0)+parseFloat(n.get(t))},对于我的视图文件中的调用:var dataSource=new Kendo.data.dataSource({…,aggregate:[{字段:“ProductName”,aggregate:“count”},{字段:“单价”,合计:“mysum”});{字段:“单价”,标题:“单价”,格式:{0:c},宽度:{120px”,页脚模板:“总和:#=mysum#”}请编辑您的问题以共享脚本和视图..在注释中以这种方式共享代码不是一种好的做法,不鼓励这样做,因此答案应该是搜索解决方案的终点(与另一个参考的中途停留相比,随着时间的推移,它往往会变得过时)请考虑在这里添加一个独立的概要,将链接作为参考。