yii2-nested-sets
yii2-nested-sets copied to clipboard
How to filter in GridView on parent?
I'm trying to filter on 'parent' of my (nested set) Category class, according to this: http://www.yiiframework.com/wiki/621/filter-sort-by-calculated-related-fields-in-gridview-yii-2-0
But it's not working I suspect because the self-join query which would normally work on a activerecord row with 'parent_id' doesn't apply here (for nested sets).
Any ideas how to get filtering by a parent working?
Help much appreciated Thanks
@gvanto - did you have any luck with extending this to search on parent in GridView?
Just CC'ing @cebe, maybe he has an idea.
@cebe, any thoughts?
Can you provide more context and semantics?
- How do you fit a nested set (tree structure) into a GridView?
- what does "filter on parent" mean? Do you want to enter a parent ID to show all children of that parent node? all direct children or all nodes below the parent?
Hi @cebe, I want to be able to filter gridview on category and parent category. I can do it on category since it is based on the name, but can't seem to find a way to filter on parent category name. This solution pulls all leaves as active records, so that is how I get the categories. Currently to get the parent, I just call ->parent(1) inside of each gridview item, which I prefer to have a relation of some sort for filter and less querying.
so what is llisted in your gridview? categories or items that are categorized (i.e. belong to a category)?
@gvanto - did you have any luck with extending this to search on parent in GridView?
Nope not looked into this for a while now. I am just listing a 'parent' column (but it's not yet filterable).
With filtering things in general on GridView, I have found that you need a pretty customized ActiveQuery in your backend/{Model}/Search class, so guessing a pretty complex AQ will be required here (not had time to look into building it though! )
@cebe In the gridview right now I just have the category and then I get the parent with $model->parents(1) in a second column.
@cebe do you have anything you can offer on this?