Answer the question
In order to leave comments, you need to log in
How to sort by a non-existent field in yii?
You need to sort in the gridView, but there is no such field anywhere. This column displays the status of the order, if there is no required record in the linked table, then the status is pending, if there is, then the status is processed. This is necessary so that the unprocessed orders are at the top of the GridView table, and the rest are sorted by date.
Answer the question
In order to leave comments, you need to log in
In theory, add a public property to the model, ala public $some_status, then write your calculated values \u200b\u200bin the selection in this property and then you can sort by it.
Here is an advanced request example:
$query = ModelName::find()
->select([
'outcome_planned.*',
'COALESCE(SUM(outcome.value), 0) AS public_field_name'
])
->with('user')
->joinWith(['outcomes'])
->groupBy('outcome_planned.id')
->orderBy(['outcome_planned.date' => SORT_DESC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 100,
],
'sort' => false
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question