Yii2:Kartik Gridview页脚的总和

时间:2015-03-21 14:19:25

标签: php mysql gridview yii2

我已经安装了Kartik gridview扩展程序,它工作正常。

但我无法在文档中找到或遗漏它,我如何在页脚中显示列的总和。

这是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>

寻求这方面的帮助。 感谢。

2 个答案:

答案 0 :(得分:6)

我认为你只需要添加页面摘要;

use kartik\grid\GridView;

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

Kartik在demo和插件详细信息中很好地描述了它。

答案 1 :(得分:2)

完整示例:

     GridView::widget([
            'dataProvider'=> $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [

            [
        'class' => 'kartik\grid\ActionColumn',
        'urlCreator' => function($action, $model, $key, $index) {
            // using the column name as key, not mapping to 'id' like the standard generator
            $params = is_array($key) ? $key : [$model->primaryKey()[0] => (string) $key];
            $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id . '/' . $action : $action;
            return Url::toRoute($params);
        },
        'contentOptions' => ['nowrap'=>'nowrap']
    ],
        'id',
        'name',

 [

'attribute'=>'total_quantity',
'pageSummary' => true

],

[

'attribute'=>'quantity_sold',
'pageSummary' => true

],

    ],
            'showPageSummary' => true
    ]);

注意:请将列类从yii \ grid重命名为kartik \ grid \。这适用于DataColum,ActionColumn等