A brief analysis of YII2 GridView Implementation dropdown Search tutorial, Yii2gridview
Not much nonsense to say, first show you, if you are still satisfied please continue to read:
How to achieve the specific? Given that there might be a number of fields for a data table to pull down, we first implement a method in its model to facilitate subsequent operations
/*** drop-down filter * @column string field * @value The value of the Mix field, returns an array of fields if not specified * @return mix returns a value or array */public static function DropDown ($colum N, $value = null) {$dropDownList = [' is_delete ' = [' 0 ' = ' + ' Display ', ' 1 ' = ' delete ', '], ' is_hot ' = [' 0 ' = = ' no ', ' 1 ' = ' = ' Yes ',],//has a new field to implement the dropdown rule, which can be added as above//...];/ /display the corresponding value according to the specific value if ($value!== null) return array_key_exists ($column, $dropDownList)? $dropDownList [$column] [$value]: false;//Returns an associative array, the user dropdown filter Implementation Elsereturn array_key_exists ($column, $dropDownList)? $dropDownList [$column]: false;}
And then we'll take a look at the code to see how it's implemented. Dropdown Search
<?= 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 implement the two drop-down effect, to implement the filtering function, in your dataprovider to customize the field to add the search criteria.
Recommended reading for the Guest house:
Analysis on the common operation of the GridView in Yii2
Yii2 the bottom of the page loading CSS and JS tips
Brief analysis of Yii2 GridView date formatting and implementation date searchable tutorials
Brief analysis of YII2 GridView implementation drop-down search tutorial
About YII2 GridView implementation of the drop-down search tutorial on the introduction of so many people, I hope to help you!
http://www.bkjia.com/PHPjc/1122883.html www.bkjia.com true http://www.bkjia.com/PHPjc/1122883.html techarticle An analysis of Yii2 GridView implementation of the drop-down search tutorial, Yii2gridview nonsense not much to say, first to show you, if you are still satisfied please continue to read: How to achieve the specific ...