本文实例为大家分享了yii2 gridView下拉列表筛选数据的具体代码,供大家参考,具体内容如下
view:
[
['class' => 'yii\grid\SerialColumn'], 'id', [
'attribute' => 'category_id', 'label'=>'类型', 'value'=>
function($model){
return $model->getCategoryName(); //值
}, 'filter' => $model->getCategoryList(),//筛选的数据
],]
model:
where(["status" => Category::STATUS_NORMAL])->asArray()->all();
if(!empty($list)){
$result = ArrayHelper::map($list,"id","category_name");
}
return $result;
}
/**
- 关联分类表
- @return \yii\db\ActiveQuery
*/
public function getCategory(){
return $this->hasOne(Category::className(),["id" => "category_id"]);
}
/**
效果: