16

Here i like to explain my problem clearly,

am trying to perform multi select dropdown filter, before this multiselect filter i have a basic filter.

Am using kartik-v dropdown extension

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
                            ],
                    ]);
?>

claimsSearch.php

$query->andFilterWhere([
            'status' => $this->status
        ]);

if i try the above code am getting error as below

Array to string conversion

but here i don't know how to write filter code.

update searchview: search view snapshot

Nodemon
  • 1,036
  • 2
  • 25
  • 47

3 Answers3

4

Try to delete 'status' from EmployeeSearch rules. You cannot filter such field automatic way. Or you must set up custom filter value for status column, like this (you can dig into this direction):

How can I use a simple Dropdown list in the search box of GridView::widget, Yii2? Try this link

Community
  • 1
  • 1
Kalai S
  • 986
  • 3
  • 14
  • 25
1

You are not calling the model in that widget. You shoudl use like this:

echo $form->field($mySearchModel, 'state_10')->widget(Select2::classname(), [
    'data' => $status,
    'options' => [
        'placeholder' => 'Select Status ...',
        'multiple' => true
    ],
]);

And your select it's probably returning an array. So, your search would be something like:

$query->andFilterWhere([
    'status' => ('in', 'status', $this->status)
]);

See more examples of queries here.

If that solution don't work, i will sugest you to do a var_dump($yourModel->status) in your view, just to check what is returning.

Clyff
  • 4,046
  • 2
  • 17
  • 32
0

$this->status is array?

So, you can use

<?php
 $status = ArrayHelper::map(Status::::model()->findAllByAttributes(array("id"=>$status));(),'id','status');
 echo $form->field($model, 'status')->widget(Select2::classname(), [
                            'data' => $status,
                            'language' => 'en',
                            'options' => [
                            'placeholder' => 'Select Status..',
                            'multiple' => true
                            ],
                            'pluginOptions' => [
                                'allowClear' => true
                            ],
                    ]);
?>
t10508hn
  • 789
  • 1
  • 5
  • 10