Unable to set pageSize for pager in CGridView - Yii

痴心易碎 提交于 2019-12-10 11:03:39

问题


I am trying to set the pageSize property of pager in CGridView but in vain. By the way currently there are total of 2 items, i want to display only 1 on 1 page. Thanks.

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'user-grid',
    'pager' => array(
        'pageSize' => 1,
    ),
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'id',
        'username',
        'email',
        'pass',
        'type',
        'date_entered',
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

回答1:


remove the following from the view

 'pager' => array(
        'pageSize' => 1,
    ),

inside the dataprovider array in your model search method add this code

$dataProvider = new CActiveDataProvider('your_model', array(
                'pagination'=>array(
                        'pageSize'=>your_page_size,
                ),
                'criteria'=>$criteria,
        ));


来源:https://stackoverflow.com/questions/18847385/unable-to-set-pagesize-for-pager-in-cgridview-yii

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!