How can I use a simple Dropdown list in the search box of GridView::widget, Yii2?

后端 未结 2 1512
迷失自我
迷失自我 2020-12-07 17:55

I am trying to make a dropdown list in the search box of a GridView::widget, Yii2 for searching related data. So, how can I create a simple dropdown list in the

相关标签:
2条回答
  • 2020-12-07 18:06

    Add this in Gridview columns array:

    [
        'attribute' => 'attribute_name',
        'value' => 'attribute_value',
        'filter' => Html::activeDropDownList($searchModel, 'attribute_name', ArrayHelper::map(ModelName::find()->asArray()->all(), 'ID', 'Name'),['class'=>'form-control','prompt' => 'Select Category']),
    ],
    

    Change values according to your attributes.

    0 讨论(0)
  • 2020-12-07 18:21

    You can also use below code

    [
        'attribute'=>'attribute name',
        'filter'=>array("ID1"=>"Name1","ID2"=>"Name2"),
    ],
    

    OR

    [
        'attribute'=>'attribute name',
        'filter'=>ArrayHelper::map(Model::find()->asArray()->all(), 'ID', 'Name'),
    ],
    
    0 讨论(0)
提交回复
热议问题