Nodemon
Nodemon

Reputation: 1046

yii2 gridview multiple select dropdown filter

I need to explain my problem clearly I have status dropdown in my application, am trying to have multi select dropdown filter.

_search.php

<?php
                $status = ArrayHelper::map(Status::find()->all(),'id','status');
                echo $form->field($model, 'status')->widget(Select2::classname(), [
                            'data' => $status,
                            'language' => 'en',
                            'options' => [
                            'placeholder' => 'Select Status..',
                            'multiple' => true
                            ],
                            'pluginOptions' => [
                                'allowClear' => true
                            ],
                    ]);
            ?>

modelSearch.php

if($this->status != null)
        {
            $query->andFilterWhere( "status IN (".implode(',',$this->status).")" );
        }

The above are my code, while am hitting search button am getting error as

PHP Notice – yii\base\ErrorException

Array to string conversion

Help me to sort out this problem...

Upvotes: 0

Views: 925

Answers (1)

sarin surendran
sarin surendran

Reputation: 303

Please try this in your modelSearch.php

if($this->status != null)
        {
            $query->andFilterWhere([ 'in','status',$this->status]);
        }

Upvotes: 0

Related Questions