This is a migrated thread and some comments may be shown as answers.

kendo grid mvvm agregate

1 Answer 260 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Veteran
Neeraj asked on 05 Feb 2019, 09:08 AM
Hello,
        How to use aggregate function in kendo mvvm grid and limit sum to 2 decimal places. sum is applied in Original Amount . Its MVVM and console error displays sum is not defined



<div data-role="grid" id="IGrid"
                data-editable='true'
                data-columns='[
                { "field": "Description", title: "Description"},
                {
                  "field": "OriginalAmount", title: "Amount", width: "100px",  editable: function () {  return false; }, template: kendo.template($("\\#GstAmount").html()),
                   footerTemplate: "Total: #=sum#")
                },
                {command:[{name:"destroy"}]}
                ]'
                data-bind='source: GST.GSTBreakup ,events: {dataBound: parent().GridDataBound}'
                style="height: 200px"></div>

1 Answer, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 05 Feb 2019, 02:56 PM
Hello, Neeraj,

The described behaviour is expected for MVVM bound grids as they are created with an empty data source initially which is without aggregates. This is explained in detail in the documentation:

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/configuration/columns.footertemplate

The solution is to provide a condition in the template, e.g.:

{ "field": "OriginalAmount", "footerTemplate": "Total: #: data.OriginalAmount? kendo.toString(sum, \"c2\"): 0 #" }

The template above will also show the sum formatted as currency with the help of the kendo.toString() method:

https://docs.telerik.com/kendo-ui/api/javascript/kendo/methods/tostring

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
MVVM
Asked by
Neeraj
Top achievements
Rank 1
Veteran
Answers by
Alex Hajigeorgieva
Telerik team
Share this question
or