Brief analysis of Yii2 GridView Implementation dropdown Search tutorial, yii2gridview_php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.