How to make the total amount in GridView Yii2 with the filters?

It is necessary in the GridView footer to display the sum of the values of certain columns in the format:
The sum of column values in GridView/the Total values.
Example

We have a column "Views". Only 5 entries, for a total of number of views - 1000.
In GridView 2 records the amount of hits they have - 200.
Have:
200/1000

The sum of column values in a GridView - implemented.
Implementation

Class:
class DataColumn extends NumberColumn
{
 private $total = 0;

 public function getDataCellValue($model, $key, $index)
{
 $value = parent::getDataCellValue($model, $key, $index);
 $this->total += $value;
 return $value;
}

 protected function renderFooterCellContent()
{
 return $this->grid->formatter->format($this->total, $this->format);
}
}

Cell columns in GV:
[
 'class' => \app\components\NumberColumn::class,
 'attribute' => 'views',
 ],



Remains the withdrawal of the total amount of values, but were below applicable filters.
Example

We have two columns "Views" and "Country".
Records:
1. V: 100, Country: EN.
2. V: 100, Country: EN.
3. V: 100, Country: EN.
4. V: 200, Country: USA.

In GridView, 2 record(1, 2) included filter Country=RU.
Final count: 200/300.
If the filter is not included, the result would be: 200/500.


How can this be achieved? In fact, you really need to pick up filters and searchModel', or to count it.
March 23rd 20 at 19:36
1 answer
March 23rd 20 at 19:38
It is not clear why it turns out 200/300, as in example 3 records EN 100, and the output should be 300/300?

It is obvious that the total amount including the filtration and in the presence of pagination (if not all of the records placed under the filter are displayed in the result) can only be obtained from a database, and to deliver such amount will be separately, using the criteria search model, but with sum() instead of find() in the end. As will be realized, the conclusion is a separate issue: it seems that will have values to pass to the view, perhaps tied to any model.

Find more questions by tags Yii