Yii2 - 如何格式化GridView中的页脚?

时间:2017-07-18 13:43:06

标签: gridview yii2 footer

这是我的GridView代码。我希望页脚与其列具有相同的格式。我该怎么做?谢谢!

echo GridView::widget([
'dataProvider' => $dataProvider,
'showFooter' => true,
'formatter' => ['class' => 'yii\i18n\Formatter','thousandSeparator' => ',','currencyCode' => 'PHP',],
        'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        [
        'attribute' =>'account_code',
        'footer' =>'Total',
        ],
        'account_name',
        [
        'attribute' =>'amount',
        'format' => 'currency',
        'footer' => Accounts::getTotal($dataProvider->models, 'amount'),
        ],

        ['class' => 'yii\grid\ActionColumn'],
        ],

]);

Picture of the table.

1 个答案:

答案 0 :(得分:0)

只需添加前缀

即可
 'footer' => 'PHP' . Accounts::getTotal($dataProvider->models, 'amount'),

并且对于千位分隔符,您可以使用number_format

'footer' => 'PHP' .
       number_format (Accounts::getTotal($dataProvider->models, 'amount'), 2 , "." ,  "," )