Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii CGridView Model Set Default Sorting Order [duplicate]

Tags:

php

yii

My Yii CGridView Sorting is not working this way when

public function search() {
   $criteria = new CDbCriteria;
   $criteria->order = "member_id DESC";

When I click header menu in CGridView it is not working but when I remove

   $criteria->order = "member_id DESC";`

sorting is working fine. I want to show records by default order by member_id desc.

like image 248
Muhammad Shahzad Avatar asked Nov 30 '22 12:11

Muhammad Shahzad


1 Answers

Remove this line $criteria->order = "member_id DESC";

Amend your return:

return new CActiveDataProvider($this, array(
    'criteria' => $criteria,
    'sort' => array(
        'defaultOrder' => 'member_id DESC',
    ),
));
like image 146
Samuel Liew Avatar answered Dec 05 '22 22:12

Samuel Liew