By Default Sort Desc Instead Of Asc In Cgridview

Hi all,

as you know cgridview sort a column ASC in first and in second click, sort will change to DESC.

I want to reverse that,

I want first click, sort the column DESC and second click, sort the column ASC.

how?

thanks :)

See http://www.yiiframework.com/forum/index.php/topic/48310-default-order-in-csort/page__gopid__225859#entry225859 - this person has som issues, but the example should inspire you.

Hi, Brother, I am glad to help you.

You need to set in your dataprovider, exactly in sort options set this

    'dataProvider'=>new CActiveDataProvider('SomeModel', array(


            'sort'=>array(


                'attributes'=>array(


                    'someField'=>array(


                        'default'=>'desc',


                    ),


                ),


            ),


        )),

Hope you will thank me.

Nurbek Nurjanov, Yii developer

Use in your model,


return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

                        'sort'=>array("defaultOrder"=>"task_id DESC")

		));