2017-03-24 36 views
0

我試圖添加一個名爲排序月在這裏GridView的頭一個自定義過濾器是對此我rewamping見下圖的前一版本的網站的一個例子enter image description here自定義過濾器DD的gridview的yii2

我一直在尋找進入的GridView的layout選項,{items}

GridView::widget([ 
     'dataProvider' => $dataProvider, 
     'filterModel' => $searchModel, 
     'layout'=>'{summary}{errors}'. \kartik\widgets\Select2::widget([ 
      'model' => $searchModel, 
      'attribute'=>'filter_month', 
      'theme' => \kartik\widgets\Select2::THEME_DEFAULT, 
      'data' => $searchModel->getFilterMonths(), 
      'pluginEvents'=>[ 
       "select2:select" => 'function() { $("#w2").submit();}', 
       // 'select2:select'=> new \yii\web\JsExpression("function(){console.log('here')}"), 
      ], 
      'options' => [ 
       'placeholder' => '--Select Month--', 
      ], 
      'pluginOptions' => [ 
       'allowClear' => true, 
       'width' => '160px', 
      ] 
     ]).'{items}{pager}', 
     'columns' => [ 
      ['class' => 'yii\grid\SerialColumn'], 
      'name', 
      'title', 
      'catalog', 
      'upc_code', 
      [ 
       'attribute' => 'created_on', 
       'label'=>'Created On', 
       'filter' => \yii\jui\DatePicker::widget(['dateFormat' => 'yyyy-MM-dd','model'=>$searchModel,'attribute'=>'created_on']), 
       'format' => 'html', 
      ], 
      [ 
       'attribute' => 'status', 
       'label' => 'Status', 
       'format'=>'raw', 
       'value' => function($data) { 
        switch ($data->status) { 
         case 0: 
          return "Being Edited (" . $data->created_on . ")"; 
          break; 
         case 1: 
          return ($data->maxdate == '') ? 'Active' :'Active'; 
          break; 
         case 2: 
          return "Expired"; 
          break; 
        } 
       }], 
      ['class' => 'yii\grid\ActionColumn'], 
     ], 
    ]); 

現在我想提交過濾器的形式,當我從下拉任何選項之前添加布局模板dropdoown,但無法弄清楚如何附上d使用下拉選項默認過濾器提交事件,以便在我選擇下拉列表中的任何選項時過濾結果。

+1

請使用t 「filterSelector」=>「#」。 Html :: getInputId($ searchModel,'AttributeName'), – ieatbytes

回答

1

對於自定義過濾器,您已使用完美的佈局,但必須爲自定義字段提供自定義選擇器。

「filterSelector」=>「#」。 Html :: getInputId($ searchModel,'AttributeName'),

+0

謝謝@ieatbytes你是對的,它開始工作就像一個魅力。 –