Aggregates refresh on row delete

6 posts, 1 answers
  1. Ruben
    Ruben avatar
    29 posts
    Member since:
    Jun 2012

    Posted 16 May 2016 Link to this post

    Hello,

    I have problem with grid aggregates.

    When data changes, on Save event everything is fine – aggregates recalculated and label updated correctly. But when row is deleted, aggregates refresh only after event Remove. As result the label shows wrong, not updated number. Is any way to work it around?

    http://jsfiddle.net/oucyngdf/

    Thank you in advance.
  2. Stefan
    Admin
    Stefan avatar
    3004 posts

    Posted 18 May 2016 Link to this post

    Hello Ruben,

    Currently the grid_RunAggregates function is called too early in the remove handler - at that time the deleted Grid row has been removed from the DOM, but the Grid has still not recalculated its aggregates. Please attach a one-time dataBound handler and execute grid_RunAggregates there.

    remove: function (e) {
      e.sender.one("dataBound", grid_RunAggregates);
    }

    http://docs.telerik.com/kendo-ui/intro/widget-basics/events-and-methods#events-Event

    In addition, it is not necessary to execute dataSource.fetch() or grid.refresh() in the remove handler. Moreover, fetching the dataSource in general will refresh the Grid automatically.

    Let me know if you need additional directions.

    Regards,
    Stefan
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Ruben
    Ruben avatar
    29 posts
    Member since:
    Jun 2012

    Posted 18 May 2016 in reply to Stefan Link to this post

    Thank you, Stefan, very much. You and your team is always very helpful.
  4. Ruben
    Ruben avatar
    29 posts
    Member since:
    Jun 2012

    Posted 20 May 2016 Link to this post

    Hello Stefan,

    There is one small problem. I've noticed, that it is not working when you delete last record. Could you take a look, please?

    http://jsfiddle.net/1gkL8c36/2/

    Thank you.

  5. Answer
    Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    1285 posts

    Posted 24 May 2016 Link to this post

    Hi Ruben,

    The described issue occurs because when the last item is deleted from the Grid, the aggregates function returns an empty object, therefore aggregates.Total becomes undefined, causing a JavaScript error when trying to access aggregates.Total.sum. You can use the following workaround in the grid_RunAggregates function:

    var total = aggregates.Total ? aggregates.Total.sum : 0;

    Let us know if you have other questions about Kendo UI.

    Regards,
    Dimiter Topalov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Ruben
    Ruben avatar
    29 posts
    Member since:
    Jun 2012

    Posted 24 May 2016 in reply to Dimiter Topalov Link to this post

    Thank you, it works!
Back to Top