yii2:在窗体视图中为Gridview定制分页 [英] yii2:Custom Pagination for Gridview in form view
问题描述
我已将Gridview小部件包含在 _form.php
文件中,该文件运行良好。
<?php
$ dataProvider = new ActiveDataProvider([
'query'=> \app\models\ServiceCharges :: find(),
'pagination'=> [
'pageSize'=> 5,
] ,
]);
?>
<?php
$ searchModel = New \app\models\ServiceChargesSearch();
$ dataProvider = $ searchModel->搜索(Yii :: $ app-> request-> queryParams);
?>
< / div>
< / div>
< div>
<?= GridView :: widget([
'dataProvider'=> $ dataProvider,
'filterModel'=> $ searchModel,
'columns'=> [
['class'=>'yii\grid\SerialColumn'],
'id',
'service_name',
'room_category' ,
'charges_cash',
'charges_cashless',
['class'=>'yii\grid\ActionColumn'],
],
]); ?>
< / div>
如果我将 $ dataprovider
分页部分位于 $ searchmodel
之下,分页工作正常,但过滤器无法正常工作,反之亦然。
如何在_form.php中使用过滤器和分页工作。
任何解决方案都将不胜感激。
感谢
我没有使用Yii2的经验,但是如果它与1相似..
为什么要声明 dataProvider
两次?我想第一个是能够自定义页面大小。
那么你会使用一个数据提供者来设置分页,然后你通过一个不同的分页
因为我可以看到 search()
方法返回一个 dataProvider
,你应该改变那里的分页。
或者我认为您可以在 search()
方法返回 dataProvider
like:
$ searchModel = New \app\models\ServiceChargesSearch();
$ dataProvider = $ searchModel->搜索(Yii :: $ app-> request-> queryParams);
$ dataProvider-> pagination-> pageSize = 5;
所以你不需要 至于过滤器,我不知道它是如何表现你的 但在Yii1中,您通常会: 1 )定义模型2)使用 I have included the Gridview widget in If I am putting the How can I have both filter and pagination working in the _form.php. Any solution will be greatly appreciated. Thanks I have no experience with Yii2 but if it is similar than 1.. Why are you declaring So what happens is you use one data provider to set pagination but then you pass a different one to the table. Second I don't know how your model looks inside but.. Since I can see the Or I think you can change it right after the So you don't need the first instance of As for the filters I do not know how it exactly behaves your But in Yii1 you normally: 1) Define model 2) Fill it up with data from If filters still not work you can provide code from the model. 这篇关于yii2:在窗体视图中为Gridview定制分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! dataProvider的第一个实例$ c
ServiceChargesSearch :: search code> function
$ _ GET
3)中的数据填充它:通过
$ model-> search()$如果过滤器仍然无法工作,您可以从模型中提供代码。
_form.php
file, which is working well. The problem is the filter and pagination.<?php
$dataProvider = new ActiveDataProvider([
'query' => \app\models\ServiceCharges::find(),
'pagination' => [
'pageSize' => 5,
],
]);
?>
<?php
$searchModel = New \app\models\ServiceChargesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
?>
</div>
</div>
<div>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'service_name',
'room_category',
'charges_cash',
'charges_cashless',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
$dataprovider
pagination part below the $searchmodel
, pagination works fine, but then filter doesn't work and vice-versa.dataProvider
twice? I imagine the first one is to be able to customize page size.search()
method returns a dataProvider
, you should change the pagination inside there.search()
method returns the dataProvider
like:$searchModel = New \app\models\ServiceChargesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->pagination->pageSize=5;
dataProvider
that you've declared before.ServiceChargesSearch::search
function
$_GET
3) Pass
$model->search()
to grid