Yii Set Item per Page CGridView dynamically

In the Controller / ActionAdmin:

 if (isset($_GET['pageSize'])) {  
           Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);  
           unset($_GET['pageSize']);  
         }  

In the model / Search Function:
 return new CActiveDataProvider(get_class($this), array(  
             'pagination'=>array(  
                 'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),  
             ),  
             'criteria'=>$criteria,  
         ));  

In the View Admin:
 <?php  
 $pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);  
 $this->widget('zii.widgets.grid.CGridView', array(  
     'id'=>'file-grid',  
     'dataProvider'=>$model->search(),  
     'columns'=>array(  
         ...,  
         array(  
             'class'=>'CButtonColumn',  
             'header'=>CHtml::dropDownList('pageSize',$pageSize,array(10=>10,20=>20,50=>50,100=>100),array(  
                  'onchange'=>"$.fn.yiiGridView.update('file-grid',{ data:{pageSize: $(this).val() }})",  
           )),  
         ),  
     ),  
 )); ?>  

...'onchange'=>"$.fn.yiiGridView.update('file-grid',{ data:{pageSize:...
change 'file-grid' to your grid view id.

result :

Comments

Popular posts from this blog

Review Pemakaian Lenovo K900 Mati Total (Matot)

VERIFIKASI SUARA MENGGUNAKAN METODE MFCC DAN DTW MENGGUNAKAN METODE MFCC DAN DTW (BAB II TINJAUAN PUSTAKA)

cara daftar di DMOZ