所以我要在gridview中进行一些调整,其中之一是将gridview显示为空白,并且仅在搜索后显示结果。我知道这是一个不寻常的调整,但这就是我被要求做的。
我不能只评论dataprovider,因为必须设置它。我可以仅凭视图就能做到吗?预先感谢
答案 0 :(得分:0)
如果已提交的过滤器参数具有值,则通过添加检验:
$searchModel = new Articles();
$query = Articles::find();
$loadData = Yii::$app->request->get();
$scope = $searchModel->formName();
$isLoadedAttributes = false;
if(isset($loadData[$scope])){
foreach($loadData[$scope] as $attributeValue){
$isLoadedAttributes = $this->isLoadedAttributes || (bool)$attributeValue;
}
}
if($isLoadedAttributes){
$query->where('1 = 2');
}else{
$searchModel->load($loadData);
}
$dataProvider = new ActiveDataProvider([
'query' => query,
]);
答案 1 :(得分:0)
做到了。如果将来有人想知道
在ProdutosSearch:
SQL> with test (id, title) as
2 (select 1, 'Robin Hood,Avatar,Star Wars Episode III' from dual union all
3 select 2, 'Mickey Mouse,Avatar' from dual union all
4 select 3, 'The Godfather' from dual
5 ),
6 temp as
7 (select regexp_substr(title, '[^,]+', 1, column_value) val
8 from test cross join table(cast(multiset(select level from dual
9 connect by level <= regexp_count(title, ',') + 1
10 ) as sys.odcinumberlist))
11 )
12 select val as title,
13 count(*)
14 From temp
15 group by val
16 order by val;
TITLE COUNT(*)
------------------------------ ----------
Avatar 2
Mickey Mouse 1
Robin Hood 1
Star Wars Episode III 1
The Godfather 1
SQL>
控制器上没有任何变化
$query = Produtos::find();
// add conditions that should always apply here
if (!isset($_GET['ProdutosSearch'])){
$query = Produtos::find();
$query->where('1 = 2');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $dataProvider;
}
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);