Is there any way to create nested filter groups? For instance, I would like to be able to have the following filters:


- Node is Published
- AND Node is Type: Special Offer
- AND Filter Group
- Field: Member Only = 0
- OR Filter Group
Field: Member Only = 1
AND User Role: Member

Thanks!

Comments

carn1x’s picture

Title: Nested Filters » Nesting Filter Groups
carn1x’s picture

Just realised I can accomplish this with the following:

- Filter Group
    - Node is Published
    - AND Node is Type: Special Offer
    - AND Field: Member Only = 0
- OR Filter Group
    - Node is Published
    - AND Node is Type: Special Offer
    - AND Field: Member Only = 1
    - AND User Role: Member

Still, it would be nice to know if my original filter set is possible, or on the radar for Views since it feels like thats the "right" way to do it :)

Just as a side of ass kissing; the more I use Views 3 the more I love it, fantastic work from those responsible!

dawehner’s picture

Status: Active » Fixed

You can only have one additional level but you can transfer any logic very easy.

Let's assume you have (A OR (B AND (C OR D)). Replace OR with a + and AND with a "x" and expand it like in math.
The result is what you want to set up.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

RollWhisTler’s picture

very nice... but what if some values are exposed? you cannot duplicate them, right? they would show duplicate entries in the exposed form...

RollWhisTler’s picture

Status: Closed (fixed) » Active

sorry, i forgot to change d'status...

m42’s picture

+1 for RollWhisTler, I'm actually facing the same problem.

hoporr’s picture

I think the solution with the math-analogy is valid from a logical standpoint, but not always practical if there are a ton of AND cases
(X1 AND X2 AND X3.... Xn) AND ( (Y1 OR Y2) AND (Y3 or Y4)) .
You'd end up having to repeat all 'n' cases of the Xs. That's maybe OK if you deal with a very small 'n,' but not so much if you have many.

Plus, as other comments showed, there are problems when some of the Xs are exposed.

Nesting would really be helpful.

I seem to remember that the old Views-Or (D6) module had nesting, did it not?

gagarine’s picture

Version: 7.x-3.0-rc1 » 7.x-3.x-dev
gagarine’s picture

Category: support » feature

Actually this is a feature request.

knsheely’s picture

+1 This feature would be very helpful. The math analogy is not practical at all in my case.

Offlein’s picture

It would be super useful to have this. For instance, I have a "keyword search" (through exposed filter) view that contains 2 different content types -- one of which has a workflow attached to it and must be in the "Approved" state. The other has no "Approved" state and will always fail if that constraint is applied. I can set them in two separate groups, but cannot set the exposed filter on both.

cferthorney’s picture

+1 . I'm trying a similar thing to Offlein but querying search_api indexes, which don't seem to call hook_views_query_alter in the same way as I would expect (I've not looked too heavily into this yet though so what I am after may be possible with a different hook) The feature would be nice whether I'm able to achieve what I need with a different hook or not.

*edit grammer and spelling tidy up*

gamesfrager’s picture

Priority: Normal » Major

I'm also in the exact same situation.
- two content types products and articles
- one content type has a field of main product the other content type doesn't have such field
- one exposed search field
- need to display results from both content types but if it's a product content type, then check if main product field is set to "yes"

Have been trying for the past few days to find a way to do this.

merlinofchaos’s picture

Priority: Major » Normal

Sorry, I won't let this go to major.

We made a conscious decision to limit the complexity available here. When you're to the point where you need to nest filter groups, it's time to just write a custom filter handler that can do the job.

gamesfrager’s picture

Fair enough, but for me and many others who don't know how to write custom code, what are the options?
I will happily use 10 other modules to allow me achieve this result. If you know of a way, please do share.

Thanks.

kpaxman’s picture

I have to say I wish for this functionality as well. If I have a number of fields that are in every group with the exact same settings, it's difficult to read and maintain. There also doesn't seem to be a way to work this with an exposed field.

Is there simple, easy-to-read documentation for creating custom filter handlers, written for beginners who have never written code for views?

andersiversen’s picture

One thing that would make things easier is if it could be possible to copy filters, especially in the organize window where you can add filtergroups and drag and drop the filters around. Say if you dragged a filter to another filtergroup, it could ask if you wanted to copy it, or maybe if you pressed shift or ctrl while dragging, it would be "copy and move" instead of move.

hazah’s picture

Issue summary: View changes

I think what would solve this problem is an ability to create a filter using rules. It works great as a validator plugin for contextual filters. Just a thought.

mvlabat’s picture

It will be a very useful feature. Looking forward for any progress in implementing this.

enboig’s picture

Any way to unlock #15? My query isn't complicated, and I could use populate filter to avoid duplicated exposed filters, but my exposed filters rely on datepicker and other javascript helpers, and "filters populate" only allow text.

Could it be overriden with query_alter with a custom module?

Thanks.

handkerchief’s picture

solideogloria’s picture

There is no way to "use math" to factor an expression if the values are Exposed Filters. Duplicating these filter items will duplicate them on the interface for the user.