creocoder / yii2-nested-sets

The nested sets behavior for the Yii framework.
Other
446 stars 129 forks source link

How to filter in GridView on parent? #115

Open gvanto opened 6 years ago

gvanto commented 6 years ago

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

blupointmedia commented 5 years ago

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

schmunk42 commented 5 years ago

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

blupointmedia commented 5 years ago

@cebe, any thoughts?

cebe commented 5 years ago

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?
blupointmedia commented 5 years ago

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.

cebe commented 5 years ago

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

gvanto commented 5 years ago

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

blupointmedia commented 5 years ago

@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 commented 5 years ago

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