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.
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.
The sum of column values in a GridView - implemented.
class DataColumn extends NumberColumn
private $total = 0;
public function getDataCellValue($model, $key, $index)
$value = parent::getDataCellValue($model, $key, $index);
$this->total += $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
We have two columns "Views" and "Country".
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.