Answer the question
In order to leave comments, you need to log in
How to make a total sum in GridView Yii2 taking into account filters?
It is necessary in the footer of the GridView to display the sum of the values of certain columns in the format:
Sum of the values of the columns in the GridView/Total sum of values.
class NumberColumn extends DataColumn
{
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);
}
}
[
'class' => \app\components\NumberColumn::class,
'attribute' => 'views',
],
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question