我显示的值如下:
1 => "活跃",0 => "无效"
1,0是db值。
这是我的专栏。
[
'label' => 'Status',
'attribute' => 'activeStatus',
'format' => 'html',
'value'=>function ($data){return $data->activeStatus ? '<span class="label label-success">Active</span>' : '<span class="label label-danger">Inactive</span>';}
],
如何使用Active/Inactive
启用网格过滤器?它可以是下拉列表,也可以只键入Active / Inactive。
答案 0 :(得分:1)
<强> GridView的强>
[
'label' => 'Status',
'attribute' => 'activeStatus',
'format' => 'html',
'value' => function ($data){
return $data->activeStatus ? '<span class="label label-success">Active</span>' : '<span class="label label-danger">Inactive</span>';
},
'filter' => [1 => 'Active', 0 => 'Inactive'],
],
<强> SearchModel 强>
public function rules()
{
return [
[['activeStatus'], 'integer'],
.
.
.
];
}
// grid filtering conditions
$query->andFilterWhere([
'activeStatus' => $this->activeStatus,
]);