Answer the question
In order to leave comments, you need to log in
How to correctly form filter values in yii2 for grid?
If anyone has come across this, please, tell me, an acceptable and correct solution for such a task:
We have:
1) 2000+ - categories
2) 1000000+ - pages
3) 50 - pages at a time displayed in the grid
Additionally: The
selection is formed on the basis of different filters from the grid.
Those. it turns out such a standard grid with filters and sorting.
What you need:
In the category filter, you need to display only those categories that are used in this selection. For example - we found 10,000 pages for different filters, but they use (all together) only 5 categories, and only these 5 categories should be present in the filter.
Answer the question
In order to leave comments, you need to log in
/** @var ActiveQuery $query */
$query = clone $dataProvider->query;
$query->select('category_id')->asArray();
Category::find()->where(['id'=>$query])->select(['name','id'])->indexBy('id')->column();
While I'm considering this option:
- I take a request from the provider (clone)
- I remove LIMIT
- Modify SELECT () in such a way that it displays only the necessary value + distinct. For example - ... select('category_id')->distinct(true) ...
Thus, I will get a list of ID's for the filter and load the filter values based on them.
Sounds like a good idea, but it's a bunch of requests. The situation becomes more complicated if there are several (if not all) such filters.
Of course, you can also enable caching when loading filter values ..
In general, maybe someone else has ideas or who has come across this?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question