Pagination Is Not Working

I created a new model using a view from MS SQL Server.

I created a adminAction in the controller and render a view using zii.widgets.grid.CGridView.

When the page is rendered first time, the pagination return the same result set, in other words, pagination not working.

On the other hand, if I use sort clicking in the column title, the pagination started to work.

Can you help me on this?

Thank you in advance…

My Code…

Controller Action

	public function actionAdmin()


		$model=new TarjetaGrupoCliente();


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









Model Search code

	public function search()


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

		// should not be searched.

		$criteria=new CDbCriteria;















		return new CActiveDataProvider($this, array(




I used pagination parameters and I had the same result.

		return new CActiveDataProvider($this, array(





			'totalItemCount' => 10,


and zii component in the admin view

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









        // Saldo de tarjeta





            	return "$ ".number_format($data->Saldo,2,",","."); 






			 'template'=>'{update} {view}' //removed {delete}



)); ?>

can you post the code (zii.widgets.grid.CGridView)?

if I use CArrayDataProvider instead of CActiveDataProvider. Can it resolve the problem?

Please, do you have any clue?

I think your Problem is in Pagination,i.e., if You are using the pagination then the totalItemCount will not return all the Rows Count,Instead it returns only less number of Counts,So set the pagination to False u will get the exact Result as in DatabaseitemCount

i think you may pass the processOutput when page render…




Thank you so much for the reply.

I used the boolean values in the page render, but the problem continues.

On the other hand, when I moved from page 5 to page 6, the page changed. The values should be in the page 2 was shown in the 6th page.

When I sort using columns name, like Saldo, the pagination working without problems.

I’m so confused.

Hi please try this remove the


on admin grid view…

i am not sure it’s work or not let’s try this:rolleyes:

I did it, but still I have the pagination problem.

Thank you,


In your search function, try adding

$criteria->distict = true;

If that does not work, have at the last two posts here. Does it solve your problem?

Thank you so much for your help!

I made the change proposed by BlkRaven.

$criteria->distinct = true;

and I had to define the primary key in this way

public function primaryKey()


return 'idTarjeta';


and I found that pagination needs define identification field if it is not id.

Finally, the pagination is working with id definition function.