Sorting On Dataprovider

Hello Everyone!!!

I have created Data provider from an user defined array.

Now I want to apply sorting based on first field. So Code for it is like :

$dataProvider->sort->defaultOrder=‘field_1 DESC’;

But, If I want to add another field for sorting like if field_1 has same value at that time it will sort based on the field_2 value.

Could you give us more details about it please ?

$dataProvider=new CArrayDataProvider($array_name, array(

'id' => 'display-grid',


'keyField' => 'user_id',


'sort'=>array(


    'attributes'=>array(


         'field_1','field_2', 'field_3','field_4','field_5'


    ),


),


'pagination'=>array(


    'pageSize'=>10,


),

));

$dataProvider->sort->defaultOrder=‘field_1 DESC’;

This is my code.

Currently sorting is done based on the "field_1" value. But I want that if 3 rows of "field_1" column has same value at that time sorting is applied on the secondary field as "field_2".

Some Example like Student data is sorted on the student’s first name but if two students have same name then it should check for the last name for those two students and sorting applied.

check something like this


return new CActiveDataProvider($this, array(

    'criteria' => $criteria,

    'sort'=>array(

        'defaultOrder'=>'field_1 DESC',

        'multiSort'=>true, //maybe your solution!

        'attributes'=>array(

           'field_1','field_2', 'field_3','field_4','field_5'

         ),

    ),

));

Its working nice but when only CGridview getting refreshed at that time this Sorting is not applied.

what did you mean ? works only the first time ?

please give the steps from start to the last step that not working

Thanks for giving your Interest!!!

I have created an array and pass that array to the Data Provider as described in previous post.

Now that Data Provider directly pass to the CGridview.

At last I have written down few AJAX code that will refresh only CGridview at every 5seconds.

So when page is loaded first time it is sorting nice but after 5-10 seconds it is not displaying data in the proper manner.

welcome :)

Are you sure that you send the aprropriate ajax-request with all CGridview parameters ?

check with firebug (network) what parameters sent (without your ajax code). Compares with your ajax one.