After searching the forum and not finding a solution, I need your help, I have a model that is related to another one and when trying to show the data, pagination does not work, when clicking on the following it keeps showing the same records, the strange thing is that If I order by some column I can use the page without problems.
my view
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'unidad-grid',
'itemsCssClass'=>'table table-hover table-striped table-bordered table-condensed',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'UniCod',
'UniNom',
array(
'name'=>'EdiNom',
'value' => '$data->ediCod->EdiNom',
),
'UniEst',
// 'UniVal',
),
)); ?>
my model:
relation:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'ediCod' => array(self::BELONGS_TO, 'Edificio', 'EdiCod'),
// 'reservas' => array(self::HAS_MANY, 'Reserva', 'UniCod'),
);
}
search:
public function search()
{
$criteria=new CDbCriteria;
$criteria->with = array('ediCod');
$criteria->compare('UniCod',$this->UniCod,true);
$criteria->compare('UniNom',$this->UniNom,true);
$criteria->compare('UniEst',$this->UniEst,true);
$criteria->compare('ediCod.EdiNom',$this->EdiNom,true);
$criteria->group = 'UniCod,UniNom,UniEst,UniVal,t.EdiCod,ediCod.EdiCod,ediCod.EdiNom,ediCod.SecCod';
$criteria->together = true;
$sort = new CSort();
$sort->defaultOrder = array( 'UniCod DESC');
$sort->attributes = array(
'EdiNom'=>array(
'asc'=>'ediCod.EdiNom',
'desc'=>'ediCod.EdiNom desc',
),
'*',
);
$dp = new CActiveDataProvider(Unidad::model(), array(
'criteria'=>$criteria,
// 'Pagination'=>FALSE,
'sort'=>$sort,
// 'pagination'=>array(
// 'pageSize'=>5,
// ),
));
$dp->setTotalItemCount(count(Unidad::model()->findAll($criteria)));
var_dump(count(Unidad::model()->findAll($criteria)));
return $dp;
}