我要添加过滤器与列表视图(有些事情喜欢在网格视图),但我不不知道如何像网格视图添加过滤器搜索列表视图Yii2
过滤器我想是的CheckBox如何做和DropDown选项。
这是我的操作代码在SiteController
<?php
public function actionMobiles(){
$searchModel = new MobileSearch();
//$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
//$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider = new ActiveDataProvider([
'query' => Mobile::find(),
'pagination' => [
'pageSize' => 1,
],
]);
// get the posts in the current page
//$posts = $dataProvider->getModels();
return $this->render('mobiles', ['dataProvider' => $dataProvider,'searchModel' => $searchModel]);
}
?>
在查看文件我有2个文件:
这里是手机浏览:
<?php
use yii\widgets\ListView;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper ;
use app\models\Mobile;
?>
<?= ListView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'itemView' => '_mobiles',
]); ?>
并在_mobiles我有:
<?php
use yii\widgets\DetailView;
?>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
//'id',
'id',
'title',
//'ativo',
],
]) ?>
它正确地显示数据库中的数据以及它的分页。 但如何添加筛选器更新列表(CheckBox和DropDown列表用于更新)?
加 'filterModel'=> $ searchModel,在你的列表视图控件 – Gunnrryy
??? @Gunnrryy – areff
设置未知属性:yii \ widgets \ ListView :: filterModel @Gunnrryy – areff