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

Best way to refresh aggregates

3 Answers 1124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dale
Top achievements
Rank 1
Dale asked on 26 Oct 2015, 08:00 PM

Details about my grid:

Kendo version 2014.2.716

Grid has the following features:Configured by Razor GridBuilder, loaded via ajax, no page size (grid scrolls internally), grouped, each row has an expandable detail row, and 6 monetary columns are aggregated, with aggregates shown in both the group footer and grid footer.

Problem: We want aggregates to update whenever you change a value in the grid.

Solution #1: Consensus seems to be to call e.sender.dataSource.fetch();  That worked, but had the following consequences:

(1) Clears dirty indicators in cells, (2) Clears any open detail rows, (3) Opens any collapsed groups.

We can solve all three of those problems manually, but it's getting to the point where I wonder if just manually updating the aggregates, for finding another way other than re-fetching would be a better solution than hacking the grid back to its pre-fetch state.  What made it extra difficult is the rows and cells are all re-created, so it's not as easy as just tracking a list of dirty cells, and marking them dirty again; you'd have to track the rowid/cellindex pair, and find the equivalent new cells.

Does anyone have any suggestions?

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 29 Oct 2015, 10:07 AM
Hello Dale,

Assuming that you are using client-side operations, the aggregates will automatically be recalculated by the dataSource on change so it should be simpler to just update the displayed aggregates than to rebind the grid and then to restore its previous state. I created an example that demonstrates redrawing just the group footers and the grid footer.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Dale
Top achievements
Rank 1
answered on 29 Oct 2015, 02:25 PM

Looks promising, thanks!  I'll try it out today.

0
Dale
Top achievements
Rank 1
answered on 30 Oct 2015, 07:00 PM

This worked perfectly, thanks!  So much better than calling fetch, and manually reconstructing the cell states (obviously).

I actually improved a bit on your code by only updating the group footer for the row which changed, rather than updating all group footers.  Process went like this:

1. Get the group for the current row from dataSource.view().
2. Get the item's row in the grid by uid.
3. itemRow.nextAll("tr.k-group-footer:first").replaceWith(grid.groupFooterTemplate(itemGroup.aggregates));

Tags
Grid
Asked by
Dale
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Dale
Top achievements
Rank 1
Share this question
or