Answer the question
In order to leave comments, you need to log in
Filters in GridView. leftJoin and andFilterWhere how to output?
I do not understand how to force the filter to be displayed. Please help with setting up a filter for related fields.
The SearchModel builds a query from two tables ' shop_product' (product_id, published, etc.) - products and 'shop_product_value' (product_id, param_id, value) - product parameter values that are linked by product_id :
$query = (new \yii\db\Query())
->select(['p.product_id', 'Опубликован' => 'p.published', 'Price' => 'p1.value', 'Description' => 'p2.value'])
->from(['p' => 'shop_product'])
->leftJoin('shop_product_value AS p1', 'p.product_id = p1.product_id AND p1.param_id IN (2)')
->leftJoin('shop_product_value AS p2', 'p.product_id = p2.product_id AND p2.param_id IN (5)')
->indexBy('product_id');
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
]);
...
$query->andFilterWhere([
'p.product_id' => $this->product_id, // генерирует поле фильтра
'p.published' => $this->published, //фильтра нет!
'p1.value' => ???????, //фильтра нет!
]);
...
return $dataProvider;
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//'columns' => $columns,
]);
Answer the question
In order to leave comments, you need to log in
you need to add public attributes to the model, describe them in rules, for sorting, describe sort in dataProvider
read:
www.yiiframework.com/wiki/653/displaying-sorting-a...
www.yiiframework.com/wiki/621/filter- sort-by-calculated
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question