CGridView and pageSize

I’m trying to have 50 or more items listed in CGridView-Widget with following code, but it doesn’t effect.

Can someone tell me why it doesn’t effect and how to fix it?

Many thanks in advance.

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






            'pageSize' => 50,









If you want to try get 50 items per page, you can try add the “Pagination” option in the controller. For example, you controller which is called if your page loading, here’s code:

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

             'Pagination' => array (

                  'PageSize' => [b]50[/b] //edit your number items per page here



hope can help you :D

Hii all,

Thanks for your help, but just a precision

‘pageSize’ can be write in the model (CActiveRecord)

public function search()


	// Warning: Please modify the following code to remove attributes that

	// should not be searched.

	$criteria=new CDbCriteria;


	return new CActiveDataProvider('Client', array(








This solution allows the user to select the number of rows per page :


In the Controlleur / ActionAdmin:

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




In the model / Search Function:

		return new CActiveDataProvider(get_class($this), array(


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




In the View Admin:



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








			          'onchange'=>"$.fn.yiiGridView.update('file-grid',{ data:{pageSize: $(this).val() }})",




)); ?>

That’s nice man! Thank you!

I follow your example and set Agent and Brokerage. I add 1/2/3 items per page for testing purposes. Only Agent view is working. Brokerage view always resets the item-per-view back to 1 in the dropdownlist even though the number of items are displayed correctly, and i have no clue why dropdownlist resets to 1 every time I select a new pagesize.

p/s: after looking closely, the setup allows different view share the same pagesize.

p/s: the dropdownlist in the non-working-view does not have [selected="selected"], why is that ?


I think I have javascript namespace conflict that prevents adding [selected="selected"], anybody know any workaround for this problem ?

Good job. Thanks for sharing.

Hey I like the View/Modify/Delete icon set, Which one is it? Do you use them on all CGridViews? If so, how do you get it to work on ALL them?

you must add this :








Is there a way to change grid row color depending on the column value,

Let say i have column bug type having values ‘GUI’,‘Usability’,‘Functional’

all the rows having bug type value as ‘GUI’ i should make row color as yellow

all the rows having bug type value as ‘Usability’ i should make row color as green

all the rows having bug type value as ‘Functional’ i should make row color as red

and for the rest of rows leave as default


	'rowCssClassExpression'=>'$data->bug == "GUI" ? "yellowClass" : ($data->bug == "Usability" ? "greenClass" : ($data->bug == "Functional" ? "redClass" : ($row%2 ? "even" : "odd")))',

hope this helps you :)

actually i want to make this dynamic, in my application i have a module where user can select one column and he will apply color codes for all the values of the column, let say

if he select bug_type column it has three values GUI, Usability, Functional where user will give a color code for values if not leave as blank, or he can select another column bug_status, it has values like New,Inprogress,Fixed,Closed where he should apply color codes for the values. For every column values are dynamic.

I have a database table like this

userid , color_column , column_value , color_code

1 , bug_type , GUI , #FF0000

1 , bug_type , Functional , #00FFFF

22 , bug_status , New , #FF0000

22 , bug_status , Inprogress , #FF0080

22 , bug_status , Fixed , #00FF00

Doesn’t a ‘row’ have the ‘htmlOptions’=> property? You might be able to go that route.

Thanks. Does anybody know how to change these globally for an app?

extending CGridView

Have you tried CWidgetFactory?

hope it helps


I did try CWidgetFactory…didn’t work :(

Somebody on the forum said that CGridView was part of the Widget Factory either.

Still looking. (hint, hint…Developement team) :rolleyes:

This is what I do: (a bit hacked I know)



class MPGridView extends CGridView{

      function init(){

    	$pageSize=user()->hasState('page-size') ? user()->getState('page-size'):20;




        	foreach($this->columns as $key=>$column){

            	if(isset($column['class'])&& $column['class']==='CButtonColumn' && !isset($column['header'])){





                    	array('onchange'=>"$.fn.yiiGridView.update('".$this->getId()."',{ data:{pageSize: $(this).val() }})")





    	return parent::init();



An extended CButtonColumn will save some typing (don’t forget to specify the extended class in the CGridView columns array)


class MyButtonColumn extends CButtonColumn


	public $viewButtonImageUrl = '../images/view.png';

	public $updateButtonImageUrl = '../images/update.png';

	public $deleteButtonImageUrl = '../images/delete.png';