washiur17 washiur17 - 1 year ago 329
PHP Question

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

I am trying to make a dropdown list in the search box of a

, Yii2 for searching related data. So, how can I create a simple dropdown list in the search box of
, Yii2 framework?


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download