2017-10-06 14 views
0

在卡爾蒂克的GridView我想與選擇2型添加濾鏡象下面這樣:filterWidgetOptions無效(yii2)

[ 
       'attribute' => 'product_id', 
       'value' => function ($model) { 
       return $model->product->name; 
       }, 
       'filterType'=>GridView::FILTER_SELECT2, 
       'filter'=>ArrayHelper::map(\app\models\ProductWord::find()->asArray()->all(), 'name', 'name'), 
       'filterWidgetOptions'=>[ 
        'pluginOptions'=>['allowClear'=>true, 'minimuminputLength' => 3], 
       ], 
       'filterInputOptions'=>['placeholder'=>'Any Product', 'multiple' => true ], 
       'group'=>true, // enable grouping 
       'label' => 'Product', 
       'headerOptions' => 
        ['style'=>'max-width: 70%; font-size: 12px;overflow: auto; word-wrap: break-word;'], 
       'contentOptions' => 
        ['style'=>'max-width: 70%; font-size: 12px;overflow: auto; word-wrap: break-word;'], 
], 

但結果是filterWidgetOptions不起作用。我想補充allowclearminimuminputLength,但它不工作。我做什麼錯王氏代碼?

謝謝

回答

0

由於搜索模式查找ID來進行搜索,你應該映射

ID

'filter'=>ArrayHelper::map(\app\models\ProductWord::find()->asArray()->all(), 'id', 'name'), 

此外,更改您的像下面一樣。你應該用你的模型來獲取值。

'value' => function ($model) { 
     return $model->product->name; 
    },