A convenient drop down to select page size and save in User state.
Step 1: On top of my controller action for the gridview (if you used CRUD, this is actionAdmin() ) i added:
// page size drop down changed
if (isset($_GET['pageSize'])) {
Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
unset($_GET['pageSize']); // would interfere with pager and repetitive page size change
}
Step2: In the model (e.g. model/User.php) the data provider in search() is configured like:
return new CActiveDataProvider(get_class($this),array(
'pagination'=>array(
'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),
),
'criteria'=>$criteria,
));
Step 3: Now the view (e.g. views/user/admin.php) :
<?php
// put this somewhere on top
$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']); ?>
<?php
// we use header of button column for the drop down
// so change the CButtonColumn in columns array like this:
...
array(
'class'=>'CButtonColumn',
'header'=>CHtml::dropDownList('pageSize',$pageSize,array(20=>20,50=>50,100=>100),array(
// change 'user-grid' to the actual id of your grid!!
'onchange'=>"$.fn.yiiGridView.update('user-grid',{ data:{pageSize: $(this).val() }})",
)),
),
Step 4: And finally the application parameter
// Accessable with Yii::app()->params['paramName']
'params'=>array (
'defaultPageSize'=>20,
Source: http://www.yiiframework.com/forum/index.php?/topic/8994-dropdown-for-pagesize-in-cgridview/