Pagination Required To Sort

Scenario… I do a search I get the results 5 per page. I have a field to sort by and it is by date. If I click to sort by date after I search it clears the page. If I click page 2 I can now sort by date go back to page 1 still works. Only on first load of the results does it not work correctly.

I look in the url in the status before I click sort by date and it is minimal at best only sort in the GET, if I change the page there are many variables being passed in GET. Now if I hover back over sort by date it is now populated with all the data from the search form.

How can I pass this data before having to call the AJAX from the pagination of the CGridView?

solution from this link

http://www.yiiframework.com/forum/index.php/topic/23340-how-to-implement-cgridview-ajax-pagination/

controller




public function actionAdmin()

        {

                $model=new PatientsFlags('search');

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

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

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


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

                        'model'=>$model,

                ));

        }



view




<?php

$model = new patientsFlags;

if(isset($_SESSION['criteria'])){

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

    'criteria'=>$model->search(), //hack to get ajax pagination to work

    'pagination'=>array(

        'pageSize'=>10,

    ),

));


?>


<?php $this->widget('zii.widgets.grid.CGridView', array(

        'id'=>'patients-flags-grid',

        'dataProvider'=>$dataProvider,

        'filter'=>$model,

        'pager'=>array('cssFile'=>Yii::app()->baseUrl.'/css/_styles.css'),

        'cssFile' => Yii::app()->baseUrl . '/css/_styles.css',

        

        'columns'=>array(

                'flag_id',

                'flag_name',

                array(

                        'class'=>'CButtonColumn',

                ),

        ),

)); 

}

?>



I’m not seeing what you are saying… Pagination works just fine, it is the sort columns that isn’t until I change the page using the pagination.

I got it the solution was passing the form POST to the sort object.




$dataProvider->getSort()->params = $postData; // From $_POST in action



I had to do the same thing with pagination to work properly with my form. Except instead of getSort it was getPagination.

Thanks anyways for your assistance.