defaultOrder String

Hi, I need use defaultOrder in my model with ActiveDataProvider, but I can´t write string.

This run correct:



         	'defaultOrder' => ['id'=>SORT_DESC]


but I need sort by a string default,

this not work:


         	'defaultOrder' => 'ABS( DATEDIFF( start_date, NOW() ) ) '


Sort object is not db specific. It can be used with ArrayDataProvider. So it’s probably impossible to use this kind of db expression in it.

But I think you can select that expression as a field and use it for sorting.

$query->select(['*', 'ABS( DATEDIFF( start_date, NOW() ) ) as dateDiff']) ...


    'defaultOrder' => ['dateDiff' => SORT_ASC]


Check also the following section of the guide.

Wou thank you, this work fine.

also I had thought that if I get the gridview order (the user check in a field for order), I use orderBy() and this work too.

For example:

        if ($CheckOrder) {

            $query->orderBy('ABS( DATEDIFF( start_date, NOW() ) )');


[color="#212121"][font="arial, sans-serif"] [/font][/color]