yii2-nested-sets icon indicating copy to clipboard operation
yii2-nested-sets copied to clipboard

How to filter in GridView on parent?

Open gvanto opened this issue 7 years ago • 9 comments

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 avatar Jan 26 '18 15:01 gvanto

@gvanto - did you have any luck with extending this to search on parent in GridView?

blupointmedia avatar May 22 '19 00:05 blupointmedia

Just CC'ing @cebe, maybe he has an idea.

schmunk42 avatar May 22 '19 06:05 schmunk42

@cebe, any thoughts?

blupointmedia avatar May 22 '19 12:05 blupointmedia

Can you provide more context and semantics?

  1. How do you fit a nested set (tree structure) into a GridView?
  2. 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?

cebe avatar May 23 '19 19:05 cebe

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.

blupointmedia avatar May 23 '19 19:05 blupointmedia

so what is llisted in your gridview? categories or items that are categorized (i.e. belong to a category)?

cebe avatar May 23 '19 20:05 cebe

@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! )

gvanto avatar May 24 '19 10:05 gvanto

@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.

blupointmedia avatar May 26 '19 14:05 blupointmedia

@cebe do you have anything you can offer on this?

blupointmedia avatar May 30 '19 22:05 blupointmedia