Answer the question
In order to leave comments, you need to log in
How to add Total row in GridView Yii2?
In general, there is a GridView from advanced
output like this:
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'date',
'operator_count',
'operator_count2',
'operator_count4',
'operator_count4',
],
]); ?>
<?php Pjax::end(); ?></div>
Answer the question
In order to leave comments, you need to log in
1) the result will have to be calculated by yourself with the help of add. functions. I do it with a helper:
<?php
namespace app\helpers;
class ArraySum
{
public static function getSum($array)
{
$sumArray=[];
foreach ($array as $k=>$subArray) {
foreach ($subArray as $id=>$value) {
$value = floatval($value);
if(isset($sumArray[$id])) {
$sumArray[$id]+=$value;
} else {
$sumArray[$id]=$value;
}
}
}
return $sumArray;
}
}
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showFooter'=>true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'date',
'operator_count'=>[
'attribute'=>'operator_count',
'footer' => $total_statistic['operator_count']
],
'operator_count2',
'operator_count4',
'operator_count4',
],
]); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question