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

Aggregates refresh on row delete

5 Answers 320 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ruben
Top achievements
Rank 1
Ruben asked on 16 May 2016, 08:28 PM
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.

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 18 May 2016, 01:31 PM
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!
0
Ruben
Top achievements
Rank 1
answered on 18 May 2016, 01:50 PM
Thank you, Stefan, very much. You and your team is always very helpful.
0
Ruben
Top achievements
Rank 1
answered on 20 May 2016, 07:39 PM

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.

0
Accepted
Dimiter Topalov
Telerik team
answered on 24 May 2016, 12:37 PM
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!
0
Ruben
Top achievements
Rank 1
answered on 24 May 2016, 01:06 PM
Thank you, it works!
Tags
Grid
Asked by
Ruben
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Ruben
Top achievements
Rank 1
Dimiter Topalov
Telerik team
Share this question
or