Dropdown Pagination Doesn't Work Correctly

Hello folks,

I am traying to make a dropdown pagination in my project, but it’s not working correctly.

Whatever the number that I select in the dropdownlist, it still shows 10 items in the page.

What I am missing ?

Thank you.

The view code :


<?php

//$dataProvider->pagination->pageSize = 25;


$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']); 

echo CHtml::dropDownList('pageSize',$pageSize,array(5=>5,10=>10,15=>15,20=>20,25=>25,30=>30),

array('onchange'=>"$.fn.yiiGridView.update('packages-grid',{ data:{pageSize: $(this).val() }})",

'empty'=>'-- Select Page Range --','style'=>'width:198px;'));


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

	'id'=>'propertylistview',

    'dataProvider'=>$dataProvider,

		'summaryText'=>'',

	'itemView'=>'_propertyview',

        'sortableAttributes' => array(

            'UnitSize',

            'PriceRent',

            'BedNo',

			'PropUnitType',

			'ProjectTitle',

			'InsertedDate'

         )

 ));

?>

The controller code :


 public function actionAdmin(){         

if (isset($_GET['pageSize'])) {

 Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);

 unset($_GET['pageSize']);}

    $model=new Packages('search');

    $model->unsetAttributes(); 

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

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

        $dataProvider=new CActiveDataProvider('Packages'); 

    $this->render('admin',array('model'=>$model,'dataProvider'=>$dataProvider,

    ));

} 

I already added this to model search


return new CActiveDataProvider(get_class($this),array(

            'pagination'=>array(

                'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),

            ),

            'criteria'=>$criteria,

    )); 

and this to config/main.php




'params'=>array('defaultPageSize'=> '10'),

Hi boot_strap,

You have to call ‘search’ method.

what do you mean ? where to call it ?can you explain please,if you don’t mind ? im a new in Yii and cooding

Thank uou in advance

You are using a CActiveDataProvider instance created in the controller. But it uses the default page size. A CActiveDataProvider instance with a customized page size is created in your "search" method. You have to call it.




public function actionAdmin(){         

    ...

    $model=new Packages('search');

    $model->unsetAttributes(); 

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

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

    // $dataProvider=new CActiveDataProvider('Packages');

    $dataProvider=$model->search();

    $this->render('admin',array('model'=>$model,'dataProvider'=>$dataProvider,));

} 



I hope the following wiki will be interesting to you.

http://www.yiiframework.com/wiki/381/cgridview-clistview-and-cactivedataprovider

Thank you for your help :)