Reputation: 674
I'm using ASP.NET webmethods
and KendoGrid
for binding the data to Grid
. The columns that are generated is dynamic. I need to apply aggregate
on each column. Please let me know how I can achieve this.
I'll not be aware of the column names that is coming from WebMethod. So not sure of how to write the aggregate. I think once the grid is loaded we can access it and then define the aggregate. Please guide. Googled on this but didn't get any help.
aggregate: [{field: "unknowncolumnnames", aggregate: "sum" }]
$.ajax({
url: "Details.aspx/DetailsWebMethod",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
$("#DetailsGrid").kendoGrid({
dataSource: {
type: "json",
data: data.Table,
pageSize: 10
},
sortable: {
mode: "single",
allowUnsort: false
},
pageable: {
input: true,
pageSizes: true,
numeric: false
},
selectable: "row",
filterable: true,
columnMenu: true,
navigatable: true,
reorderable: true,
resizable: true,
groupable: false,
scrollable: false
});
}
});
Upvotes: 2
Views: 1872
Reputation: 36
$.ajax({
url: "",
datatype: "JSON",
type: "GET",
success: function (result) {
var items = $.parseJSON(result)[0];
var arrCol = [];
var arrAgg = [];
for (var index in items)
{
arrCol.push({ field: index, format: "{0:0}", footerTemplate: "#= kendo.toString(sum, '0.00') #" });
arrAgg.push({ field: index, aggregate: "sum" });
}
console.log(arrAgg);
if (result.Result.length > 0) {
var dataSource = new kendo.data.DataSource({
data: $.parseJSON(result.Result),
group: { field: "Category" },
aggregate: arrAgg
});
$('#divgrid').html("");
$("#divgrid").kendoGrid({
dataSource: dataSource,
height: "auto",
scrollable: false,
sortable: true,
groupable: false,
columns: arrCol
});
Upvotes: 2