Yii CGridView default Order
If you want to set a default sort order for a CGridView, often used in admin views you can do so in the controller or models as part of the search() function like bellow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public function search() { $criteria = new CDbCriteria; $criteria->alias = ''; //db table alias $criteria->select = ''; //select query here $criteria->compare('t.id', $this->item_name); $criteria->compare('t.store_id', $this->category_id); return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'pagination' => array( 'pageSize' => 20, ), 'sort' => array('defaultOrder' => 'category_id, item_name') )); } |