Pawan Pawan - 7 months ago 345
SQL Question

Yii2: Kartik Gridview sum of a column in footer

I have installed the Kartik gridview extension, which is working fine.

But I couldn't find or missed it in the docs, how I can show the sum of a column in the footer.

This is my complete code in

index.php


<?php
$gridColumns = [
['class' => 'yii\grid\SerialColumn'],
'id',
[
//'attribute'=>'service_name',
'attribute'=>'service_name',
'value'=>'serviceName.services',
],
[
'attribute'=>'room_category',
'value'=>'roomCategory.room_category'
],
'charges_cash',
'charges_cashless',
['class' => 'yii\grid\ActionColumn']
];

echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
'fontAwesome' => true,
'showPageSummary' => true,
'dropdownOptions' => [
'label' => 'Export All',
'class' => 'btn btn-default'
]
])
?>
</div></div>


<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'id',
//'service_name',
[
//'attribute'=>'service_name',
'attribute'=>'service_name',
'value'=>'serviceName.services',

],
// 'room_category',
[
'attribute'=>'room_category',
'value'=>'roomCategory.room_category'
],
'charges_cash',
'charges_cashless',

['class' => 'yii\grid\ActionColumn'],
],
'showFooter' => true
]); ?>

</div>


Looking for some help on this one.
Thanks.

Answer

I think you just need to add the page summary;

use kartik\grid\GridView;

// Create a panel layout for your GridView widget
echo GridView::widget([
    'dataProvider'=> $dataProvider,
    'filterModel' => $searchModel,
    'columns' => $gridColumns,
    'showPageSummary' => true
]);

Kartik describes it pretty well in the demo and plugin details.