CListView

Hi,

i’m using CListView widget to show some paginated data. I have set the sortableAttributes and everything is working ok.

But, when i click in a sortable attribute (for example, list of cars, velocity attribute) the order is ascending by default. I want the inverse, i want that when i click in "velocity", the fastest car has to be the first (descending) not the last (ascending, default behaviour).

Sorry for my english.

Specify the ‘default’ option in ‘attributes’ property of CSort:

http://www.yiiframework.com/doc/api/1.1/CSort#attributes-detail

You need to do this in the controller.

Gstar, it works like a charm. Thank you very much.

This is my final solution, maybe it can helps someone in the future:




$CdataProvider = new CActiveDataProvider('Car', array(

                'pagination' => array(

                    'pageSize'=>10

                ),

                'criteria' => array(

                    'with' => array('extra'),

                    'together' => true,

                    'condition' => 'extra.id='.$id,

                ),

                'sort' => array(

                    'attributes' => array(

                        'name' => array(

                            'default' => 'asc',

                            'asc' => 't.name',

                            'desc' => 't.name desc',

                        ),

                        'speed' => array(

                            'default' => 'desc',

                        ),

                    ),

                ),

            ));



Thanks again.