2017-10-06 54 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; 
    },