title: how to customize a filter for GridView using Search Model?
body: <p>I'm using a gridview widget in yii2.</p>
  
  <p>in my search view file:</p>
  
  <pre><code>$gridview=GridView::widget([
      'dataProvider' =&gt; $dataProvider,
      'filterModel' =&gt; $searchModel,
      'columns' =&gt; [
          [
              'attribute'=&gt;'id',
              'width'=&gt;'10%'
          ],
          [
              'attribute'=&gt;'status_id',
              'value'=&gt;function ($data) {
                  return $data-&gt;statusOption[$data-&gt;status_id];
              },
             'filterType'=&gt;GridView::FILTER_SELECT2,
             'filter'=&gt; Problem::getStatusOption(),
          ],
          [
              'attribute'=&gt;'content',
          ]
      ]
  ]);
  </code></pre>
  
  <p>now i've already customized the search model to support filtering the items by multiple status_id as following.</p>
  
  <p>in my ItemSearch Model file:</p>
  
  <pre><code>class ItemSearch extends Item
  {
      public $sids=[];
  
      public function rules()
      {
          return [
              [['status_id'], 'integer'],
              [['sids'], 'safe'],
          ];
      }
  
      public function query($params)
      {
          $this-&gt;load($params);
  
          $query = Item::find();
  
          $query-&gt;andFilterWhere([
              'status_id' =&gt; $this-&gt;status_id,
          ]);
  
          if(!empty($this-&gt;sids))
          {
              $query-&gt;andWhere(['in','status_id',  $this-&gt;sids]);
          }
      }
  
      public function search($params)
      {
          $query=  $this-&gt;query($params);
  
          $dataProvider = new ActiveDataProvider([
              'query' =&gt; $query,
              'pagination' =&gt; [
                  'pageSize' =&gt; 10,
              ],
          ]);
  
          return $dataProvider;
      }
  }
  </code></pre>
  
  <p>now i put an adidtional select box outside the grid. which is a little ugly with a submit button aside.</p>
  
  <p>in my search view file:</p>
  
  <pre><code>&lt;?php $form = ActiveForm::begin([
          'method' =&gt; 'get',
  ]);?&gt;
  
  &lt;div class="form-group"&gt;
      &lt;select class="status" name="ItemSearch[sids][]" multiple="true"&gt;
            &lt;option value="0"&gt;status 0 &lt;/option&gt;
            &lt;option value="1"&gt;status 1 &lt;/option&gt;
       &lt;/select&gt;
      &lt;button class="btn btn-success" type="submit"&gt;submit&lt;/button&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>i store the selected status in an array for js things.</p>
  
  <pre><code>echo "var stSelect = ".\yii\helpers\Json::encode($searchModel-&gt;sids).";\n"
  </code></pre>
  
  <p>i want to make the following button group work.</p>
  
  <pre><code>&lt;div class="btn-group" data-toggle="buttons"&gt;
  &lt;?php foreach(Problem::getStatusOption() as $key=&gt;$val):?&gt;
      &lt;label class="status-button btn btn-default &lt;?= in_array($key, $searchModel-&gt;sids)?"active":''?&gt;" data-key="&lt;?=$key?&gt;"&gt;&lt;input type="checkbox"&gt;&lt;?= $val?&gt;&lt;/label&gt;
  &lt;?php endforeach;?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>so i write some js using Jquery:</p>
  
  <pre><code>$('.status-button').on('click', function(){
      stSelect = toggle(Number($(this).attr("data-key")),stSelect);
      $('.status').val(stSelect);
  })
  
  var toggle = function(value,array){
      if(array.indexOf(value) &gt; -1) {
          array.splice(array.indexOf(value),1)
      }else{
          array.push(value)
      }
      return array
  }
  </code></pre>
  
  <p>but now i have following problems to handle with:</p>
  
  <ul>
  <li><p>everytime i submit the form, the get params send to the controller just simply add to the last params. </p>
  
  <p>for example, in 1st submit, i select status 0.</p>
  
  <p>stSelect={"0"}</p>
  
  <p>in 2rd submit i select status 0 and 1.</p>
  
  <p>stSelect={"0","0","1"}</p>
  
  <p>but the original filter works fine.</p></li>
  <li><p>i need to click submit to refresh the grid. how to let grid to update when click the button group buttons?</p></li>
  </ul>