CListView: Pagination not working

Hi all,

I have the issue that my pagination is not working.

When I deactive the pagination for my CListView the calculated amount of Items and the displayed items are correctly displayed.

E.g. Displaying 1-3 of 3 result(s).

If I activate my pagination by adding the pagination setting


 return new CActiveDataProvider('User', array('criteria' => $criteria,'pagination'=>array(

        'pageSize'=>'2',

    ),   ));

I get an active pagin with the Page 1 and 2, but one item is missing.

On the First Page I get this message: Displaying 1-1 of 3 result(s).

My Code for the View:




<?php

Yii::app()->clientScript->registerScript('search', "

		$('.search-form form').submit(function(){

			$.fn.yiiListView.update('ajaxListView', {

				data: $(this).serialize()

			});

			return false;

		});

		");




....


<div id="searchresult" class="row">

		<h2>Gefundene Coaches: </h2>

		<?php

			$this->widget('zii.widgets.CListView', array(

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

				    'itemView'=>'_listview',

				    'id'=>'ajaxListView',

					'enablePagination'=>true,

			));

		?>

	</div>







My Code in my Controller:





public function actionCashgamecoach()

	{

		$this->setFullLayout();


		....


		$model=new User('coachsearch');

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

		$model->id_gametype = GameType::ID_CASHGAME;


		

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

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


		$this->render('cashgamecoach',  array('model' => $model, ...);

	}




and finally my Code in my User Model:





public function search()

{

         ...

        $criteria = $this->mainsearch($subcriteria);


        return new CActiveDataProvider('User', array('criteria' => $criteria,'pagination'=>array(

        'pageSize'=>'2',

    ),   ));

    }

}



Any suggestion why the result is not displayed properly?

Thanks and regards!

Oliver

What’s in the criteria? For instance (IIRC) there may be an issue with group and limit. Relationship with or without together?

/Tommy

Hi Tommy,

in this case we have a lot of joins but without groups. We are using distinct in one case.

The Search consists of two Select statements. The Search is preparing a select stament with “together” to find all users. The condition is passed to the mainsearch where we retrieve all the found users with the user_id’s.




public function search()

{

         ...

        $criteria = $this->mainsearch($subcriteria);


        return new CActiveDataProvider('User', array('criteria' => $criteria,'pagination'=>array(

        'pageSize'=>'2',

    ),   ));

    }

}



then we build for the found users a select statement with a criteria and return it to the function search.




    private function mainsearch($subcriteria, $orderBy = "lastlogin DESC")

    {





        $userfound = User::model()->active()->validemail()->completeprofile()->findAll($subcriteria);




        $criteria=new CDbCriteria;

        $criteria->select = 'username';

        $criteria->with = array('userskillconfigs'=>array('select' => false,

            'joinType'=>'LEFT JOIN',

        ),

            'userprofile'=>array(		'select' =>'userprofile.picture, userprofile.dateofbirth, userprofile.coachsince',

                'joinType'=>'LEFT JOIN',

            ),

            ....

        );

        $criteria->together = true;


        $criteria->order = $orderBy;


        $values = array();

        foreach($userfound as $user){

            Yii::log('USER FOUND ID'.$user->id, 'INFO', $this);

            $values[] = $user->id;

        }


        $criteria->addInCondition('t.id', $values);


        return $criteria;

    }



Is there any mistake?

I think it might be because together is true (assuming HAS_MANY relationship). Thus all tables are joined in one query even when a limit (2 in this case) is applied.

This post has a good explanation. Also see the fourth paragraph in this section of the guide.

/Tommy

Thanks for your support! I will give it a try :)