Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - 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' => 'yiigridSerialColumn'],
    'id',
    [
        //'attribute'=>'service_name',
        'attribute'=>'service_name',
        'value'=>'serviceName.services',                
    ],
    [
        'attribute'=>'room_category',
        'value'=>'roomCategory.room_category'
     ],
        'charges_cash',
        'charges_cashless',
    ['class' => 'yiigridActionColumn']
];

    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' => 'yiigridSerialColumn'],

            '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' => 'yiigridActionColumn'],
        ],
         'showFooter' => true
    ]); ?>

</div>

Looking for some help on this one. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you just need to add the page summary;

use kartikgridGridView;

// 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...