【问题标题】:Kendo UI Grid sum aggregate on a column with an optional propertyKendo UI Grid sum 在具有可选属性的列上聚合
【发布时间】:2014-06-13 00:54:18
【问题描述】:

我使用Aggregates feature of a Kendo UI Grid Widget 来显示分组列的总和。有问题的列绑定到一个可选字段/属性,因此当数据集包含属性不存在(即未定义)的数据项时,总和最终为NaN,正如您所期望的那样。

Kendo DataSource calculates these aggregates "when the data source populates with data"does not include a feature to allow custom aggregates 可以让我实现一个 sum 版本,用 0 代替未定义的值。

我可以看到 sum 聚合函数在 kendo.data.js 中定义的位置,但如果可能的话,我不希望更改它。

我知道如何通过编写一个函数来查询$("#myGridId").data("kendoGrid").dataSource 来解决这个问题,但我想知道是否有更好的选择。

【问题讨论】:

    标签: kendo-ui telerik kendo-grid


    【解决方案1】:

    在将kendo.data.js 中的最新代码与我的项目版本 (2013.1.319) 进行比较后,我发现他们已经更改了 sum 聚合函数的实现以仅通过执行加法来处理这种情况如果值是一个数字。如果我可以将项目更新到最新版本的 Kendo UI,问题就解决了。

    下面的代码sn-p在2014.1.416版本的第1369行。

    sum: function(accumulator, item, accessor) {
        var value = accessor.get(item);
        if (!isNumber(accumulator)) {
            accumulator = value;
        } else if (isNumber(value)) {
            accumulator += value;
        }
    
        return accumulator;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 2017-09-07
      • 2015-05-13
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多