owaisosha
(owaisosha)
1
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']
]);
1 Like
evstevemd
(Stefano Mtangoo)
2
for parameter required for sorting see: Sort, yii\data\Sort | API Documentation for Yii 2.0 | Yii PHP Framework
$sort = new Sort([
'attributes' => [
'age',
'name' => [
'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC],
'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC],
'default' => SORT_DESC,
'label' => 'Name',
],
],
]);
More on that:
Displaying Data: Sorting | The Definitive Guide to Yii 2.0 | Yii PHP Framework
TLDR;
3 Likes
owaisosha
(owaisosha)
3
1 Like