2

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

我试图在网格中求和,如果我使用 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))}
4

1 回答 1

0

你好我迟到了,但如果它可以帮助某人。

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

链接到这里的项目

function myAggregate(data){
 // Data here is a list of data by group (brilliant right! :-) )
 // Do anything here and return result string
}

var grid = $('#grid').kendoGrid({
  ...
  columns: [
  { field: '', title: '', groupFooterTemplate: myAggregate
  ]
  ...
});
<!DOCTYPE html>
<html>
  <head>
    <!-- YOUR CSS HERE -->
  </head>
  <body>
    ...
    <div id="#grid"></div>
    ...
    <script>// jQuery here </script>
    <script>// kendo.all.min.js here </script>
    <script src="kendo.aggregate.helper.js"></script>
  </body>
</html>

于 2016-01-13T10:12:56.627 回答