Yii2 - Grid multi select filter not working

3.3k views Asked by At

I am using gridView::FILTER_SELECT2 with multiple = TRUE and AllowClear = TRUE.

Problem 1: When I select single option it works fine but when I select another option it overwrites the first option and filter accordingly.

$gridColumns[] = [
            'attribute'=>'clubName',
            'headerOptions'=>[
                'style'=>'width: 15%'
            ],

            'filterType'=>GridView::FILTER_SELECT2,
            'filter'=>Clubs::getClubs(),
            'filterWidgetOptions'=>[
            'pluginOptions'=>['allowClear'=>true,
                'tags' => true,
                'tokenSeparators' => [',', ' '],
                'maximumInputLength' => 10
                ],
            'options'=>['id' => 'unique-select2-id'],


            ],
            'filterInputOptions'=>['placeholder'=>'Select Club'],
            'value' => function($model, $key, $index, $column){
                    return urldecode($model->header->club->name);
                },

        ];
<?= GridView::widget([
            'headerRowOptions'=>['class'=>'kartik-sheet-style'],
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'pjax' => true,
            'responsive' => true,
            'pjaxSettings' => [
                'options' => [
                    'enablePushState' => false,
                    'options' => ['id' => 'unique-pjax-id'] // UNIQUE PJAX CONTAINER ID
                ],

            ],
            'columns' => $gridColumns,

            'panel'=>[
                'type'=>GridView::TYPE_PRIMARY,
                'heading'=>$this->title,
            ],

            // set your toolbar
            'toolbar'=> [
                ['content'=>''

                ],
                '{export}','{toggleData}'

            ],
// set export properties
'export'=>[
            'fontAwesome'=>true
        ],

            'showPageSummary'=> true,
        ]); ?>

Problem2: When I try to remove selected option by clicking x , it doesn't clear the selection and throwing js error.

TypeError: args is undefined --- args.prevented = true;
1

There are 1 answers

0
Igor  Lytvynenko On

It looks like there is a related issue in yii2 tracker https://github.com/yiisoft/yii2/issues/4431