diff --git a/slick.dataview.js b/slick.dataview.js index f1c1b5e34..2fd61e606 100644 --- a/slick.dataview.js +++ b/slick.dataview.js @@ -7,7 +7,8 @@ Avg: AvgAggregator, Min: MinAggregator, Max: MaxAggregator, - Sum: SumAggregator + Sum: SumAggregator, + Count: CountAggregator } } } @@ -1120,6 +1121,28 @@ } } + function CountAggregator(field) { + this.field_ = field; + + this.init = function () { + this.sum_ = 0; + }; + + this.accumulate = function (item) { + var val = item[this.field_]; + if (val != null && val !== "") { + this.sum_ += 1 + } + }; + + this.storeResult = function (groupTotals) { + if (!groupTotals.sum) { + groupTotals.sum = {}; + } + groupTotals.sum[this.field_] = this.sum_; + } + } + // TODO: add more built-in aggregators // TODO: merge common aggregators in one to prevent needles iterating