Pagesize On Cgridview

Hi everyone,

I’ve a small problem.

I’m using yii-user extension.

I have in UserController.php the following function

	public function actionIndex()


		$dataProvider=new CActiveDataProvider('User', array(












… and the following view (index.php)

$this->widget('zii.widgets.grid.CGridView', array(


	'itemsCssClass' => 'border-lines',

	'htmlOptions' => array('class' => 'border-lines-table user-table'),



        'pager'=> array(



		'htmlOptions' => array('class'=>'pagination pagination-lg'),

		'prevPageLabel'  => '<',

		'nextPageLabel'  => '>',

		'firstPageLabel' => '&laquo;',

		'lastPageLabel'  => '&raquo;',

		'selectedPageCssClass' => 'active',

		'maxButtonCount' => 10




			'name' => 'username',


			'value' => 'CHtml::link(CHtml::encode($data->username),array("user/view","id"=>$data->id))',



			'name' => 'createtime',

			'value' => 'date("d.m.Y H:i",$data->createtime)',



			'name' => 'lastvisit',

			'value' => '(($data->lastvisit)?date("d.m.Y H:i",$data->lastvisit):UserModule::t("Not visited"))',




Number of items (users) per page is always 10 even if I set 20.

Anyone can help me? Thanks

Assuming you are using the search method in your model, add this to your gridview:




    'header'=>CHtml::dropDownList('pageSize',$pageSize,array(10=>10,20=>20,50=>50,100=>100),array('onchange'=>"$.fn.yiiGridView.update('modelname-grid',{ data:{pageSize: $(this).val() }})")),


Change ‘modelname-grid’ to contain your model name (lowercase).

Add this to the appropriate action in your controller.


        $pageSize = Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']);

        if (isset($_GET['pageSize'])) {

            $pageSize = $_GET['pageSize'];

            Yii::app()->user->setState('pageSize', (int) $_GET['pageSize']);



        $this->render('index', array(

            'model' => $model,

            'pageSize' => $pageSize,


Update your search method as follows:


        return new CActiveDataProvider($this, array(

            'criteria' => $criteria,

            'pagination' => array(

                'pageSize' => Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']),



You can now change the page size on the fly.

Thanks, but I’m not using the search method.

I would set 20 records per page and no other options.

How can I do?

I’ve used this option with search method in other Controller and it works fine; not here. Why?