DESC最后用NULLS排序?

时间:2017-11-24 14:58:03

标签: php sorting yii2

如何在我的列表中放置NULLS来设置默认的DESC排序?我的代码的一部分负责排序:

$dataProvider->sort->defaultOrder = ['created_at' => SORT_DESC];
$dataProvider->sort->attributes['created_at'] = [
    'asc' => [Production::tableName().'.created_at' => SORT_ASC],
    'desc' => [Production::tableName().'.created_at' => SORT_DESC]
];

此致

1 个答案:

答案 0 :(得分:1)

试试这个:

$dataProvider->sort->attributes['created_at'] = [
    'asc' => [new Expression(Production::tableName().'.created_at ASC NULLS FIRST')],
    'desc' => [new Expression(Production::tableName().'.created_at DESC NULLS LAST')]
];
$dataProvider->sort->defaultOrder = ['created_at' => SORT_DESC];