Answer the question
In order to leave comments, you need to log in
How to organize sorting by date in Yii in CActiveDataProvider?
In general, the date is stored in datetime in the database. I output data and change the date format when outputting. How can I sort by this field?
CActiveDataProvider code:
$tripsData = new CActiveDataProvider('Trips',[
'criteria'=>$criteriaToday,
'pagination' => [
'pageSize' => $this->per_page
],
'sort'=>[
'attributes' => [
'id',
'place',
'target',
'execution_date',
'date',
],
'defaultOrder'=>[
'id'=>'DESC',
]],
]);
Answer the question
In order to leave comments, you need to log in
it was necessary to specify the name of the attribute in column.
[
'name' => 'date',
'type' => 'raw',
'value' => 'strtotime($data->date) ? date(\'dmY H:i\', strtotime($data->date)) : \'\'',
],
And it doesn't work?
'defaultOrder'=>[
'date'=>'DESC',
]],
sort
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question