Does anyone have a step by step example of how to use server aggregates with the kendoTreeList? The documentation is skimpy and the examples don't work. In my case, I'm doing lazy loads from the server with each expand. The totals in the grid keep changing and the only way to prevent that is to have the totals come from the server or the data source before it binds. Below is a sample. Any help would be much appreciated.
return new kendo.data.TreeListDataSource({
transport: {
read: function (options) {
var dataUrl;
var level; // assumes that level will be hte name of the display column, and level + "ID" will be the name of the id column
var parentId = options.data.id || null;
if (options.data.id == null) {
level = "P";
dataUrl = GLOBAL_WEBAPIBASEURL + "/api/Trading/GetTradeMVByGrouping?GroupBy=PositionType&StartDate=" + from + "&EndDate=" + to + "&FundId=" + GLOBAL_FUNDID + "&BUId=" + GLOBAL_BUID + "&SBUId=" + GLOBAL_SBUID;
} else if (options.data.id.indexOf('P') == 0) {
level = "D";
var p = options.data.id.replace('P-', '');
dataUrl = GLOBAL_WEBAPIBASEURL + "/api/Trading/GetTradeMVDetail?StartDate=" + from + "&EndDate=" + to + "&FundId=" + GLOBAL_FUNDID + "&BUId=" + GLOBAL_BUID + "&SBUId=" + GLOBAL_SBUID + "&PositionType=" + p;
}
//console.log('Exposure By Class ' + level);
//console.log(newquery);
$.ajax({
url: dataUrl,
dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
success: function (result) {
var data = [];
var results;
var agg = [];
var totalBuy = 0, totalSell = 0, totalNet = 0;
for (var i in result) {
switch (level) {
case "P"://Parent
data.push({ label: result[i].PositionType, entity: result[i].PositionType, id: level + "-" + result[i].PositionType, display: result[i].PositionType, parentId: parentId, hasChildren: true, level: 0 });
break;
case "D"://Detail
data.push({ label: result[i].Inst, entity: result[i].Inst, entityId: result[i].InstId, id: level + "-" + result[i].InstId, display: result[i].Inst, parentId: parentId, hasChildren: false, level: 1 });
break;
}
totalBuy += parseFloat(result[i].Buy);
totalSell += parseFloat(result[i].Sell);
totalNet += parseFloat(result[i].Buy) - parseFloat(result[i].Sell);
data[i].BuyGMV = result[i].Buy;
data[i].SellGMV = result[i].Sell;
data[i].Net = result[i].Buy - result[i].Sell;
}
agg = "{\"TotalBuyGMV\":{\"sum\":" + totalBuy + "}, \"TotalSellGMV\":{\"sum\":" + totalSell + "}, \"TotalNet\":{\"sum\":" + totalNet + "}}";
results= "{\"data\": " + JSON.stringify(data) + ", \"aggregates\": " + agg + "}";
// notify the data source that the request succeeded
options.success(JSON.parse(results));
},
error: function (result) {
// notify the data source that the request failed
options.error(result);
}
});
},
},
schema: {
data: "data",
//aggregates: "aggregates",
model: {
id: "id",
}
},
serverAggregates:true,
aggregate: [
{ field: "TotalBuyGMV", aggregate: "sum" },
{ field: "TotalSellGMV", aggregate: "sum" },
{ field: "TotalNet", aggregate: "sum" }
],
sort: { field: "Net", dir: "desc" }
});