1
votes

I am trying to sum a column on a kendo grid, the datasource is not server side data, and the column is defined like this.

data-columns="[
    ...
    { 'field': 'owing', title: 'Balance Owing', format: '{0:c}', aggregates:['sum'],attributes: { style: 'text-align: right;'},groupFooterTemplate:'#= sum #' },
    ...

And the datasource has grouping and aggregates added like this

selectedTransactions.group({
    field: "company",
    aggregates: [
        { field: "owing", aggregate: "sum" }
    ]
});
selectedTransactions.aggregate([{ field: "owing", aggregate: "sum" }]);

I can't find anything else in kendo or anywhere saying I need to add more, but I am gettign an exception

Uncaught ReferenceError: sum is not defined

2
you're trying to get the sum of the amount of values in the column?Keith
@Keith the values are currency, I want the sum of money owing in the selected transactions, so I want the sum of the amounts in that group of the column, grouped by company.Andrew

2 Answers

2
votes

What you need to do is add aggregate in your datasource:

 aggregate: [ { field: "owing", aggregate: "sum" } ],

and then in your columns add a footer template to collect the sum of the entire column:

 { field: "owing", title: "Total Price", footerTemplate: "Total Amount: #=sum#" }
-1
votes

Here in kendo grid sum keyword is use here as variable so you Just Declared sum variable in var sum = 0; top of the code when we use sum then sum keyword declared as local variable