Kendo ui grid创建聚合函数

时间:2013-09-05 13:12:56

标签: javascript kendo-ui

有没有办法在ken​​do中创建聚合函数?

我正在尝试在网格中进行求和,如果我使用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
 });

kendo ui添加了功能:

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

1 个答案:

答案 0 :(得分:0)

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

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

链接到项目here



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>
&#13;
&#13;
&#13;