[英]yii2 dropdown in gridview widget filter
I want to make a closed dropdownlist values in the Gridview widget of YII2 framework.我想在 YII2 框架的 Gridview 小部件中创建一个关闭的下拉列表值。 the code i have now:
我现在拥有的代码:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [ //only fields name!
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
'statusId',
'categoryId',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
and statudId should be one of 3 possible values.并且 statudId 应该是 3 个可能的值之一。 (1-open, 2-in progress, 3-closed)
(1-打开,2-进行中,3-关闭)
Hi the answer is simple from what you think.您好,根据您的想法,答案很简单。
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
//don't use this:
//'statusId',
//use this instead:
[
'attribute' => 'statusId',
'filter' => [ "1"=>"open", "2"=>"in progress", "3"=>"closed" ]
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
That's how you need to do it:这就是你需要做的:
[
'attribute'=>'column_name',
'label'=>'LABEL OF COLUMN',
'filter'=>array("first"=>"first","second"=>"second"), // you can read from database directly
'value' => function ($data) {
return $data->column_name;
}
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.