I want to display total of row vaules in footer.
I have tried several ways but doesn't show proper result.
Any help will be highly appriciated.
I am using kartik grid.
I have tried this Yii2: Kartik Gridview sum of a column in footer
but doesn't work in my case.
$gridColumns = [
[
'class' => 'kartik\grid\SerialColumn',
'contentOptions' => ['class' => 'kartik-sheet-style'],
'width' => '36px',
'header' => '',
'headerOptions' => ['class' => 'kartik-sheet-style']
],
[
'attribute' => 'vno',
'footer'=>'Total'
],
[
'attribute' => 'fliters',
'label' => 'Total Fuel Consumption Liters',
'footer'=> true // Here i want to display the sum of column filer ( Note : the value in grid of filter is a sum(fuel_liters) )
],
[
'attribute' => 'fuel_rate',
'label' => 'Fuel Rate (Per Ltr.)',
'pageSummary'=>true,
'footer'=>true // Here i want to display the sum of column fuel_rate ( Note : the value in grid of filter is a sum(fuel_rate) )
],
[
'attribute' => 'famt',
'label' => 'Total Fuel Consumption Amount',
'pageSummary'=>true,
'footer'=>true // Here i want to display the sum of column fuel_amount ( Note : the value in grid of filter is a sum(fuel_amount) )
],
];
echo GridView::widget([
'dataProvider'=> $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'showPageSummary' => true
]);
So far I manage to print total in footer
Im my Controller i have wriiten this
$total_ltrs = FuelConsumption::find()->sum('fuel_liters');
$total_amt = FuelConsumption::find()->sum('fuel_amount');
$total_rate = FuelConsumption::find()->sum('fuel_rate');
return $this->render('petrol-report', [
'total_ltrs' => $total_ltrs,
'total_amt' => $total_amt,
'total_rate' => $total_rate,
'model' => $model,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
And passed 'footer'=>$total_ltrs
'footer'=>$total_rate
and 'footer'=>$total_amt
Respectively in all footers.
Now when i do search throgh From Date and TO Date the result is dislaying in grid as per filter.
But the Result of Total in footer keeps unchanged. I want to do some of only those rows which are in grid.
Can anybody help me on this ??