这是我的DataProvider:
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => ['pageSize' => 50],
'sort' => [
'defaultOrder' => [
'priority' => SORT_DESC,
'date_targeted' => SORT_ASC
]
]
]);
我想要的是移动("未设置")到结果的末尾。
我该怎么做?
答案 0 :(得分:2)
您可以在select
中添加新字段。并在IF
案例中设置:
$query->select([
'*',
new \yii\db\Expression('IF(date_targeted IS NULL, 1, 0) AS date_targeted_flag')
]);
在sort
添加date_targeted_flag
:
'sort' => [
'defaultOrder' => [
'date_targeted_flag' => SORT_ASC,
'priority' => SORT_DESC,
'date_targeted' => SORT_ASC
],
'attributes' => [
'date_targeted_flag',
'priority',
'date_targeted'
]
]