Modify header cell depending of grid filtering

Hi guys,

So here is what I am trying to do: I have a grid of people. Each cell represents a certain amount of time spent by the person on an activity. The header of the column represents the average time spent. Currently to do the average, I call a method to get all persons from the DB and then I make an average. But what I want to do is to dynamically modify this average depending on the filtering of the grid.

How can I do that? ListDataProvider isn’t modified when filtered so I found this solution to get the number of rows
grid.getDataProvider().size(new Query<>())

However this only returns the number of rows. What I want is to get access to each element of the cells in order to redo the calculation of the average.

Is there a way to do it?

The easiest would be to use this method if it would be public, especially assuming your data source is not huge, as you are using ListDataProvider