Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 data provider default sorting

In Yii 1.1 this code works for default sorting:

$dataProvider = new CActiveDataProvider('article',array(     'sort'=>array(         'defaultOrder'=>'id DESC',     ), )); 

How default sorting can be set in Yii2?

Tried below code, but no result:

$dataProvider = new ActiveDataProvider([     'query' => $query,     'sort' => ['defaultOrder'=>'topic_order asc'] ]); 
like image 340
nsv Avatar asked Apr 10 '14 16:04

nsv


1 Answers

I think there's proper solution. Configure the yii\data\Sort object:

 $dataProvider = new ActiveDataProvider([      'query' => $query,      'sort'=> ['defaultOrder' => ['topic_order' => SORT_ASC]],  ]); 

Official doc link

like image 77
Alex Avatar answered Sep 22 '22 16:09

Alex