我正在尝试对CGridView
using进行分页CArrayDataProvider
(我$rawData
是自定义数组 - 不是来自数据库/模型)。因此,在控制器的操作中具有以下内容:
$form = new SearchUser;//here I have SearchUser form that extends CFormModel with the following attributes: 'id', 'name', 'surname', 'phone', 'address'
$users = array();
if (isset($_POST['SearchUser'])) {
....//prepare users array from my custom source-> not from DB/models etc
}
$dataProvider=new CArrayDataProvider($users, array(
'id'=>'id',
'keys'=>array('name', 'surname', 'phone', 'address'),
'sort'=>array(
'attributes'=>array(
'name', 'surname', 'phone', 'address'
),
),
'pagination'=>array(
'pageSize'=>15,
),
));
和:
$this->render('index', array('dataProvider'=>$dataProvider, 'form'=>$form));
在 index.php 我有:
...
<?php echo CHtml::link('Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$form,
)); ?>
</div><!-- search-form -->
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'name' => 'Name',
'type' => 'raw',
'value' => 'CHtml::encode(@$data["name"])'
),
array(
'name' => 'Surname',
'type' => 'raw',
'value' => 'CHtml::encode(@$data["surname"])'
),/*
array(
'name' => 'Phone',
'type' => 'raw',
'value' => 'CHtml::encode(@$data["phone"])'
),*/
array(
'name' => 'Address',
'type' => 'raw',
'value' => 'CHtml::encode(@$data["address"])'
),
),
'enablePagination'=> true,
));
第一页显示正确,但是当我选择另一页时,我的过滤器丢失了,所有数据都显示在网格中,而不是“过滤”的数据。