首页 > 其他 > 详细

YII2 gridview

时间:2017-02-23 14:02:37      阅读:198      评论:0      收藏:0      [点我收藏+]

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‘],
],

  

  

  

YII2 gridview

原文:http://www.cnblogs.com/yangyuqiu/p/6432954.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!