Answer the question
In order to leave comments, you need to log in
How to make a connected multi-sort in ActiveDataProvider?
Good afternoon,
sorting by additional table in ActiveDataProvider does not work
$query = User::find()
->leftJoin(Table::tableName().' p','user.id = p.user_id');
$this->processPageRequest('page');
$provider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 3,
'page' =>\Yii::$app->request->get('page'),
],
]);
$provider->setSort([
'defaultOrder' => [],
'attributes' => [
'table.xx1' => \Yii::$app->request->post('xx1') == 3 ? SORT_ASC: SORT_DESC,
'table.xx2' => \Yii::$app->request->post('xx2') == 3 ? SORT_ASC: SORT_DESC,
'table.xx3' => \Yii::$app->request->post('xx3') == 3 ? SORT_ASC: SORT_DESC,
]
]);
Answer the question
In order to leave comments, you need to log in
Where is join?
with is eager loading. Loading a connection hasMany in one request. And it happens after the main request.
You need to add joinWith www.yiiframework.com/doc-2.0/guide-db-active-recor...
Next:
$dataProvider->sort->attributes['xx1'] = [
'asc' => ['table.xx1' => SORT_ASC],
'desc' => ['table.xx1' => SORT_DESC],
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question