No more nonsense, first to show you the effect of the picture, if you are still very satisfied please continue reading:
Specifically how to achieve Nan? Considering a data table to pull down the effect of the field may have many, we first in its model to implement a method to facilitate subsequent operations
/** * Drop-down
filter
* @column string field
* @value the corresponding value of the Mix field, not specified returns the field array
* @return Mix returns a value or array/public
s tatic function DropDown ($column, $value = null)
{
$dropDownList = [
' is_delete ' => ['
0 ' => ' show '] c11/> ' 1 ' => ' delete ',
],
' is_hot ' => [
' 0 ' => ' no ',
' 1 ' => ' is ',
],
///There is a new field to implement the dropdown rule , and can be added as above
//...
];
Display the corresponding value based on the specific value
if ($value!== null) return
array_key_exists ($column, $dropDownList)? $dropDownList [$column] [$value]: false;
Returns the associative array, the user Drop-down filter implementation
else return
array_key_exists ($column, $dropDownList)? $dropDownList [$column]: false;
}
And then we'll take a look at the code to see how the dropdown search is implemented
<?= gridview::widget ([
' Dataprovider ' => $dataProvider,
' columns ' => [/
...
] [
' attribute ' => ' is_hot ', '
value ' => function ($model) {return
Article::d ropdown (' Is_hot ', $model- >is_hot);
},
' filter ' => Article::d ropdown (' Is_hot '),
],
[
' attribute ' => ' Is_ Delete ',
' value ' => function ($model) {return
Article::d ropdown (' Is_delete ', $model->is_delete);
} ,
' filter ' => Article::d ropdown (' Is_delete '),
],
//... ...
]
;?>
Like this, we simply implemented a two drop-down effect, to implement the filtering function, in your dataprovider to add the field of the search criteria can be.
Recommended readings for cloud-dwelling communities:
Simple analysis of common operation of GridView in Yii2
Yii2 the bottom of the page load CSS and JS tips
Brief analysis of YII2 GridView date format and date to search tutorials
A brief analysis of YII2 GridView implementation Drop-down Search Tutorial
About YII2 GridView implementation of the Drop-down search tutorial to introduce so many people, I hope to help you!