kendo grid mvvm agregate

2 posts, 0 answers
  1. Neeraj
    Neeraj avatar
    128 posts
    Member since:
    May 2015

    Posted 05 Feb Link to this post

    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>
  2. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    793 posts

    Posted 05 Feb Link to this post

    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.
Back to Top