Kendo ui grid create aggregate function
Is there a way to create an aggregate function in kendo?
I am trying to make a sum in a grid, if I use the sum function defined by
kendo it just concatenates the numbers like they are string. My actual
solution is to change the js from kendo and to put there mysum function.
It works like a charm but there should be a better solution, I think.
View code:
var dataSource = new kendo.data.DataSource({ pageSize: 20, data: products,
autoSync: true, schema: { model: { id: "ProductID", fields: { ProductID: {
editable: false, nullable: true }, ProductName: { validation: { required:
true } }, Category: { defaultValue: { CategoryID:
1,CategoryName:"Beverages"} }, UnitPrice: { type: "number", validation: {
required: true,min: 1} } } } }, aggregate: [ { field: "ProductName",
aggregate: "count" }, { field: "UnitPrice", aggregate: "mysum" }] });
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 430,
toolbar: ["create"],
columns: [
{ field: "ProductName", title: "Product Name",
footerTemplate: "Total Count: #=count#" },
{ field: "Category", title: "Category", width:
"160px", editor: categoryDropDownEditor, template:
"#=Category.CategoryName#" },
{ field: "UnitPrice", title:"Unit Price", format:
"{0:c}", width: "120px", footerTemplate: "Total
Sum: #=mysum#" },
{ command: "destroy", title: " ", width: "90px" }],
editable: true
});
And kendo ui added function:
mysum:function(e,t,n){return (e || 0) + parseFloat(n.get(t))}
No comments:
Post a Comment