Home > Backend Development > PHP Tutorial > yii2 GridView drop-down search implementation case tutorial android gridview usage .net gridview c gridview

yii2 GridView drop-down search implementation case tutorial android gridview usage .net gridview c gridview

WBOY
Release: 2016-07-29 08:52:27
Original
900 people have browsed it

Author: Bailang Source: http://www.manks.top/article/yii2_gridview_dropdown_search The copyright of this article belongs to the author, and you are welcome to reprint it. However, this statement must be retained without the author’s consent, and a link to the original text must be provided in an obvious position on the article page. Otherwise, we reserve the right to pursue legal liability.

Pull down the search, let’s take a look at the expected renderings first

android gridview,gridview属性,c# gridview,gridview android,asp.net gridview,gridview 分页,android gridview用法,.net gridview,c gridview

How to achieve it specifically? Considering that a data table may have many fields that require drop-down effects, we first implement a method in its model to facilitate subsequent operations

/**
 *  下拉筛选
 *  @column string 字段
 *  @value mix 字段对应的值,不指定则返回字段数组
 *  @return mix 返回某个值或者数组
 */
public static function dropDown ($column, $value = null)
{
    $dropDownList = [
        'is_delete'=> [
            '0'=>'显示',
            '1'=>'删除',
        ],
        'is_hot'=> [
            '0'=>'否',
            '1'=>'是',
        ],
        //有新的字段要实现下拉规则,可像上面这样进行添加
        // ......
    ];
    //根据具体值显示对应的值
    if ($value !== null) 
        return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false;
    //返回关联数组,用户下拉的filter实现
    else
        return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false;
}
Copy after login

Then we go to the code to see how to implement the drop-down search

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        // ......
        [
            'attribute' => 'is_hot',
            'value' => function ($model) {
                return Article::dropDown('is_hot', $model->is_hot);
            },
            'filter' => Article::dropDown('is_hot'),
        ],
        [
            'attribute' => 'is_delete',
            'value' => function ($model) {
                return Article::dropDown('is_delete', $model->is_delete);
            },
            'filter' => Article::dropDown('is_delete'),
        ],
        // ......
    ],
]); ?>
Copy after login

Like this, we Simply implement two drop-down effects. To implement the filtering function, just add the search conditions for this field in your dataProvider.

The above introduces the yii2 GridView drop-down search implementation case tutorial, including GRIDVIEW content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template