YII2 Gridview
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了YII2 Gridview相关的知识,希望对你有一定的参考价值。
YII2 Gridview 部分使用规则
1.页面显示的时间戳转换
a.
[
‘label‘=>‘创建日期‘,
‘attribute‘ => ‘created_at‘,
‘filter‘ => false, //不显示搜索框
‘value‘ => function($data) {
return date(‘Y-m-d H:i:s‘,$data->created_at); }
],
b.
[
‘label‘=>‘创建日期‘,
‘attribute‘ => ‘created_at‘,
‘format‘ => [‘date‘, ‘php:Y-m-d H:i:s‘],
],
2.为字段加超链接
[
‘attribute‘=>‘title’,
‘format‘=>‘raw’,
‘value‘=> function($data){return html::a($data->title,[‘exam/index‘,
‘id‘ => $data->_id],[‘title‘ => ‘审核‘]);}
],
[
‘label‘=>‘更多操作’,
‘format‘=>‘raw’,
‘value‘ => function($data) {
$url = "http://www.baidu.com”;
return Html::a(‘添加权限组‘, $url, [‘title‘ => ‘审核‘]); }
],
3.下拉菜单搜索
[
‘label‘ => ‘当前状态‘,
‘attribute‘ => ‘status‘,
‘filter‘ => Html::dropDownList(‘AppBaseSearch[status
]‘,$searchModel-> status,
[ ‘‘ => ‘请选择‘,
‘0‘ => ‘审核拒绝‘,
‘1‘ => ‘审核通过‘,
]),
‘value‘ => function($date) {
switch ($date-> status) {
case 1‘;
return ‘审核通过‘;
break;
case ‘0‘;
return ‘审核拒绝‘;
break;
default:
return ‘未知状态‘;
break;
}
}
],
4.私人定制增删改按钮
[
‘header‘ => "查看/审核",
‘class‘ => ‘yii\grid\ActionColumn‘,
‘template‘=> ‘{view} {update} {delete}‘,
‘headerOptions‘ => [‘width‘ => ‘140‘],
‘buttons‘ => [
‘view‘ => function ($url, $model, $key) {
return Html::a(Html::tag(‘span‘, ‘‘, [‘class‘ => "glyphicon fa fa-eye"]), [‘admin/view-app‘, ‘id‘=>$model->app_id], [‘class‘ => "btn btn-xs btn-success", ‘title‘ => ‘查看‘]);
},
‘update‘ => function ($url, $model, $key) use($uid){
return Html::a(‘通过‘, [‘admin/reviewapp‘,‘id‘=>$model->app_id, ‘status’=>1], [‘class‘ => "btn btn-xs btn-info"]);
},
‘delete‘ => function ($url, $model, $key) {
return Html::a(‘拒绝‘, [‘admin/reviewapp‘, ‘id‘ => $model->app_id, ‘status’=>0], [‘class‘ => "btn btn-xs btn-danger"]);
}
]
],
以上是关于YII2 Gridview的主要内容,如果未能解决你的问题,请参考以下文章