Yii2 Gridview - 如何在页脚属性上使用总计 [英] Yii2 Gridview - How use totals on footer property

查看:35
本文介绍了Yii2 Gridview - 如何在页脚属性上使用总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 VALUE 列是:

<预><代码> ['属性' =>'价值','格式' =>'生的','contentOptions'=>['style'=>'width: 10%;text-align:left'],'页脚' =>???],

如何使用 FOOTER 属性上的行总数?

解决方案

有效1.创建类然后2.创建列数组,3.配置列,4.配置网格

namespace app\components;类 PTotal {公共静态函数 pageTotal($provider, $fieldName){$总=0;foreach($provider as $item){$total+=$item[$fieldName];}返回 $total;}$provider = new ActiveDataProvider(['查询' =>$查询,'排序' =>$排序,]);$grid_columns=[['属性' =>'saldo_in','footer'=>PTotal::pageTotal($provider->models,'saldo_in'),]]回声 GridView::widget(['数据提供者' =>$提供者,'showFooter'=>TRUE,'footerRowOptions'=>['style'=>'font-weight:bold;text-decoration: underline;'],'列' =>$grid_columns,]);

My VALUE column is:

    [
     'attribute' => 'value',
     'format' => 'raw',
     'contentOptions'=>['style'=>'width: 10%;text-align:left'],
     'footer' => ???
    ],

How use totals of rows on FOOTER property ?

解决方案

it's works 1. create class then 2.create column array, 3.configure column, 4.configure grid

namespace app\components;
class PTotal {
public static function pageTotal($provider, $fieldName)
{
    $total=0;
    foreach($provider as $item){
        $total+=$item[$fieldName];
    }
    return $total;
}
$provider = new ActiveDataProvider([
'query' => $query,
'sort' => $sort,
]);


$grid_columns=[         
[
    'attribute' => 'saldo_in',
    'footer'=>PTotal::pageTotal($provider->models,'saldo_in'),
]
]

echo GridView::widget([
'dataProvider' => $provider,
'showFooter'=>TRUE,
'footerRowOptions'=>['style'=>'font-weight:bold;text-decoration: underline;'],
'columns' =>$grid_columns,
]); 

这篇关于Yii2 Gridview - 如何在页脚属性上使用总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆