0
我試圖按兩個字段對數據源進行分組,並獲得其值的平均值或總和。 但即使我在數據源中同時指定了組和屬性,我也無法得到它。KendoUI數據源組和由多個字段聚合
下面是代碼:
var dataSource = new kendo.data.DataSource({
data: [
{ id: 1, name: "Amazon US", stock: 15, year: 2015},
{id: 2,name: "Amazon US", stock: 20, year: 2016 },
{id: 3,name: "Amazon US", stock: 7, year: 2016 },
{ id: 4, name: "Amazon EU", stock: 30, year: 2015 },
{ id: 5, name: "Amazon EU", stock: 7, year: 2015 },
{ id: 6, name: "Amazon EU", stock: 12, year: 2016 },
{ id: 7, name: "Amazon EU", stock: 26 , year: 2016}
],
schema: { // required if get method will be used
model: {
id: "id"
}
}
})
dataSource.read();
dataSource.bind("change", function() {
var log = $("#log");
log.append("<P>total records in datasource is " + this.total() + "</p>" );
var A = this.aggregates();
log.append("<p>total stock is " + A.stock.sum + "</p>");
})
.aggregate({ field: "stock", aggregate: "sum" });
在這裏工作的例子: http://jsfiddle.net/rusev/NwG9A/2/
的總和預期的結果應該是:
- AmazonUS | 2015 | 15
- AmazonUS | 2016 | 27
- AmazonEU | 2015 | 37
- AmazonEU | 2016 | 38
有沒有人有線索,如果這可能與KendoUI數據源?
http://jsfiddle.net/3M2XR/364/我corectlly明白了嗎? – calinaadi