Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 dropdown in gridview widget filter

Tags:

php

yii2

I want to make a closed dropdownlist values in the Gridview widget of YII2 framework. the code i have now:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [ //only fields name!
        ['class' => 'yii\grid\SerialColumn'],

        'id',
        'title',
        'statusId',
        'categoryId',
       ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>

and statudId should be one of 3 possible values. (1-open, 2-in progress, 3-closed)

like image 531
laury Avatar asked Jul 25 '16 21:07

laury


1 Answers

Hi the answer is simple from what you think.

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel'  => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'title',
            //don't use this:
            //'statusId',
            //use this instead:
            [
                'attribute' => 'statusId',
                'filter'    => [ "1"=>"open", "2"=>"in progress", "3"=>"closed" ]
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
like image 120
YaakovHatam Avatar answered Oct 19 '22 21:10

YaakovHatam