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		


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

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

			

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

			'model'=>$model,

		));

		

	}



Model Search code




	public function search()

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('idTarjeta',$this->idTarjeta);

		$criteria->compare('nroTarjeta',$this->nroTarjeta,true);

		$criteria->compare('FechaVigDesde',$this->FechaVigDesde,true);

		$criteria->compare('FechaVigHasta',$this->FechaVigHasta,true);

		$criteria->compare('FechaEstadoTarjeta',$this->FechaEstadoTarjeta,true);

		$criteria->compare('Saldo',$this->Saldo,true);

		$criteria->compare('idEstadoTarjeta',$this->idEstadoTarjeta,true);

		$criteria->compare('Descripcion',$this->Descripcion,true);

		$criteria->compare('idCliente',$this->idCliente);

		$criteria->compare('RazonSocial',$this->RazonSocial,true);

		$criteria->compare('idGrupo',$this->idGrupo);

		$criteria->compare('Nombre',$this->Nombre,true);

		$criteria->compare('idTitularTarjeta',$this->idTitularTarjeta);

		$criteria->compare('ApellidoyNombre',$this->ApellidoyNombre,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}



I used pagination parameters and I had the same result.




		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

			'pagination'=>array(

				'pageSize'=>5,

			),

			'totalItemCount' => 10,

		));



and zii component in the admin view





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

	'id'=>'tarjeta-grid',

	'dataProvider'=>$model->search(),

	'enablePagination'=>true,

	'filter'=>$model,

	'columns'=>array(		

		array(			

            'name'=>'nroTarjeta',            

        ),

        // Saldo de tarjeta

		array(

		    'htmlOptions'=>array('width'=>'100px','align'=>'right'),			

            'name'=>'Saldo',

            'value'=>function($data,$row){

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

            },

        ),		

		array(

			//'name'=>'Acciones',

			'class'=>'CButtonColumn',

			 '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…


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

                        'model'=>$model,

                ),false,true);



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


 'enablePagination'=>true,

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,

Hi

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.