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}
),
),
)); ?>