Setting CGridView page size


I have one table which records I would like to display in a gridview but without using pagination and keeping the filter and sorting functionalities.

If I use CActiveDataProvider I can set the

$dataProvider->pagination->pageSize = $model->count()

but I loose the filtering capabilities because an error message is displayed saying: [color="#0000FF"]CActiveDataProvider does not have a method named "getValidators".[/color]

In this case, if I set the CGridView->filter property to $model no errors are shown, but the filters do not work.



$dataProvider = new CActiveDataProvider($model);

/* The idea is to show all the table's records in the gridView without using the pager */

$dataProvider->pagination->pageSize = $model->count();




                  'dataProvider'=>$dataProvider,   // This helps to establish the pageSize property.

                  'filter'=>$model,	// This keeps the filters in the gridview but don't work.



                  'summaryText' => '{count} records(s) found.',


I wish to have filtering and sorting capabilities (as in any normal gridView) and show all the records with a code like this:

	$contacts = new Contact;

	$dataProvider = new CActiveDataProvider('Contact');

	$dataProvider->pagination->pageSize = $contacts->count();










              	'summaryText' => '{count} records(s) found.',

              	'columns'=>array( ...

but this approach generates the error: [color="#0000FF"]CActiveDataProvider does not have a method named "getValidators".[/color]

Is there any way to show all the records in a gridView without using pagination?

Any ideas?


there is a CDataProvider.setPagination method to disable pagination.


$dataProvider = new CActiveDataProvider($model);


// ...

If you just don’t want to display the pager define a template in your grid and leave it out.

'template' => '{items}{summary},

Enfield, the idea is not only to get rid of the pager. My goal is to show all of the table’s records but by default Yii shows only the first 10 records in a gridView.

I don’t want my gridView to show just a bunch of records, but all of them.

Sorry, I forgot to mention this detail in my original post.

[size="6"]SOLVED !![/size]

Ok, after reading this post, published by Trejder:


I started to experiment on my own code and I realized what my problem was.


I didn’t need to create another CActiveDataProvider to feed my CGridView widget, because the variable $model (a CActiveRecord instance) provides an instance of CActiveDataProvider in its search method. So, for my model class I just had to make a small change to make sure that the search method returns all the records from the table:

public function search() {

   $criteria = new CDbCriteria;




   return new CActiveDataProvider(get_class($this), array('criteria'=>$criteria, 'pagination'=>array('pageSize'=>$this->count())) );


Normally, the Gii tool generates this method to return something like this:

return new CActiveDataProvider(get_class($this), array('criteria'=>$criteria, ));

but in my case I had to add the pagination parameter and set its pageSize property to the total count of records in the table.


In the controller, the method that calls the script that contains the CGridView widget can look like this:

public function actionDonations() {

   $model = new Contact('search');

   $model->unsetAttributes();  // clear any default values

   // This condition is to update the $model variable with the last change posted with the filters in the gridView.

   if (isset($_GET['Contact']))

  	$model->attributes = $_GET['Contact'];	

   $this->render('donations', array('model'=>$model));


[size="3"]Finally [/size]

The CGridView widget can use the normal $model variable as dataProvider:









 		'summaryText' => '{count} records(s) found.',

 		'columns'=>array( ... )


With this little changes I get rid of the pager and show all records in the table.