YII2 gridview

4. 数据列显示枚举值(男/女)


[ 'attribute' => 'sex', 'value'=>function ($model,$key,$index,$column){ return $model->sex==1?'男':'女'; }, //在搜索条件(过滤条件)中使用下拉框来搜索 'filter' => ['1'=>'男','0'=>'女'], //or 'filter' => Html::activeDropDownList($searchModel, 'sex',['1'=>'男','0'=>'女'], ['prompt'=>'全部'] ) ], [ 'label'=>'产品状态', 'attribute' => 'pro_name', 'value' => function ($model) { $state = [ '0' => '未发货', '1' => '已发货', '9' => '退货,已处理', ]; return $state[$model->pro_name]; }, 'headerOptions' => ['width' => '120'] ]

3. 数据列有链接

 [
   'attribute' => 'title',
   'value' => function ($model, $key, $index, $column) {
            return Html::a($model->title, 
                ['article/view', 'id' => $key]);
    },
   'format' => 'raw',
],

2. 处理图片

[
    'label'=>'封面图',
    'format'=>'raw',
    'value'=>function($m){
        return Html::img($m->cover,
                    ['class' => 'img-circle',
                    'width' => 30]
        );
    }
],

1. 处理时间

[
 'label'=>'更新日期',
 'format' => ['date', 'php:Y-m-d'],
 'value' => 'updated_at'
],

//or
[
 //'attribute' => 'created_at',
 'label'=>'更新时间',
  'value'=>function($model){
        return  date('Y-m-d H:i:s',$model->created_at);   
  },
 'headerOptions' => ['width' => '170'],
],

  

  

  

posted @ 2017-02-23 12:54  Yeah,程序猿  阅读(365)  评论(0编辑  收藏  举报