Initialy set CListView to last page

How do I set CListView widget initialy to the last page?

That’s a good question. Anyone?

ORDER BY DESC ;)

Here is a working example on the actionIndex:




	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('model',array(

			'pagination'=>array(

				'pageSize'=>10,

			)

		));

		$pager=$dataProvider->pagination;

		$pager->itemCount=$dataProvider->totalItemCount;

		if(!Yii::app()->request->isAjaxRequest)

			$pager->currentPage=$pager->pageCount;


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

			'dataProvider'=>$dataProvider,

		));

	}



Thanks, mdomba, works perfect!

Hi this works well, but if i have a GET variable for the page index, it overwrites it, anyway to work around? For example:


$dataProvider=new CActiveDataProvider('model',array(

                        'pagination'=>array(

                                'pageSize'=>10,

                                'pageVar'=>'page',

                        )

                ));




Thanks

OK, I think this should work?


if(!Yii::app()->request->isAjaxRequest && !Yii::app()->request->getQuery('page'))

	$pager->currentPage=$pager->pageCount;

Hi.

The example provided above by Maurizio does not display the last page when it is an ajax request.

I want to display the last page for all requests (including ajax requests) - except if it is a pagination request - obviously because you want to display the selected page in such case.

How do you determine if it is a pagination ajax request?

UPDATED WITH ANSWER:

Add a custom parameter to the url of the pager. Then in your code you can test if such parameter was included in $_GET - to know if it was an ajax pagination request.




$pagerparams = $_GET; 

$pagerparams['pagerFlag'] = '1';

		

$dataProvider = new CActiveDataProvider($this, array(

	'pagination'=>array(

		'params'  => $pagerparams,

	),

	...


));


...


if(Yii::app()->request->isAjaxRequest)

{

	if(array_key_exists('pagerFlag', $_GET))

	{

		...

	}

}