CGridView pagination problem

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(
 	'itemsCssClass'=>'table table-hover table-striped table-bordered table-condensed',
             'value' => '$data->ediCod->EdiNom',
 		// 'UniVal',
 )); ?>

my model:

  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'),


 public function search()
 		$criteria=new CDbCriteria;
 		$criteria->with = array('ediCod');
 	  	$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(
 			    'desc'=>'ediCod.EdiNom desc',
 		 $dp = new CActiveDataProvider(Unidad::model(), array(
             // 'Pagination'=>FALSE,
 	  		// 'pagination'=>array(
 			  //     'pageSize'=>5,
 			  //   ),
 	  return $dp;

Does the JOIN produce unique rows or are you getting duplicate entries?

You may need to add a distinct option to the query.

thank you for the answer, the count give the correct numbers of rows, i try with defaultOrder in sort and works fine but the sort not work in any column from page two in pagination.

This looks suspicious to me. The dataprovider should be able to figure out the correct number of items itself.

What happens if you remove these two lines and add distinct to the query?

I took those commands from another forum with the same problem, for now I can not do the test in the afternoon I can barely try what you say, thanks for the reply