First I must say that views is probably the most powerful module I have ever used. This might already be possible but I have been trying and trying and have not been able to make it work.
What I'm trying to do is create a taxonomy vocab. "Age". I have populated it with individual ages. Now I would like to be able to create a view that offers a filter based on a range of those ages.
Basically something like:
Age
From _____ To ______
Where the user has a drop down box to select for the "From" to the "To" area. Maybe taxonomy isn't the way to go on this and just creating a field via CCK with individual ages might be a better option. Either way my problem is how to create the range in views. Is there an argument I could maybe use or something I am missing?
Comments
Comment #1
merlinofchaos commentedCreate two filters on age. For one operator, set it to >= and the other to <=. Click 'expose' on both. In the exposed filters box, set the label on the >= one to 'From', set it to Lock Operator and not optional. Set the label on 'To', lock operator, not optional.
Comment #2
orionvortex commentedI'm stuck with exposing the filters. It only will let me expose one filter per field.
Comment #3
orionvortex commentedmerlinofchaos, you don't know how badly i wish i had your knowledge! I'm so lost on this. So far I have created CCK integer text field with CCK and I can make two filters for that field in views but I can only expose it once. Maybe I didn't quite understand your suggestion. I'm sure though that views can accomplish this task but I'm just a little lost on what I am doing wrong.
Comment #4
merlinofchaos commentedOn further reflection it may not be possible to expose the same field twice due to the IDs.
I'd always though that would be possible.
Uh. This is a bug. :/
Comment #5
orionvortex commentedIf this is a bug it sounds like one that can't be fixed very easily. Should I just scrap this idea and move on?
Comment #6
merlinofchaos commentedFor now, yes; and you're right, it won't be easily fixable.
Comment #7
RobRoy commentedHeh, I just came across this need for CCK decimal value where I want a range.
On a side note, is there any way to create an argument with an operator like <=? Meaning I'd like two args for this decimal field, one to be less than one to be greater than. This would be nice, but I suppose that this is what expose filters is for. Any hints on this bug?
Anyone found a workaround?
Comment #8
RobRoy commentedUgh...I was asking if there was a way to assign operators to arguments so you could have two args with one being less than the given arg, and the other being greater than or whatever. I know it's like exposed filters so I guess there isn't any reason to want that.
Anyone found a workaround for this?
Comment #9
karens commentedIt would take a new argument or some changes to existing ones, but I am thinking this has possibilities -- arguments that can be specified as '=' (the way it works now) or '<', or '>'. Then you could stack a greater than and less than argument to filter your range.
Not sure right now how you would indicate which operator you wanted the argument to use, it would seem logical to prefix your argument with the operator (i.e. change '10' to '>10' and follow it by an argument with '<12'). but that won't work because you can't use =, <, or > in an url. Maybe some other indicator in the argument could work, or maybe it could be done with options.
I don't have any time to work on this myself right now, but I might play around with it later if no one else does it.
Comment #10
orionvortex commentedI'm going to play around with it too. Hopefully I can figure out some solution for it. I have a feeling that this is something dealing with the core code of drupal so merlinofchaos might not be able to produce a patch for views very easily. I think this mainly because this guy created probably the most powerful module in all of drupal so obviously he his a very talented developer and towards the beginning of this thread he said it won't be easily fixable. Hopefully we can all work together and figure something out for this but I wouldn't keep too much of my hopes up for a fix...at least not for a while.
Comment #11
RobRoy commentedI'd really like to see this functionality and could throw a little donation to anyone who get's this working inside views. Let me know if anyone is working on this currently and maybe we could collaborate as well.
Comment #12
sja1 commentedI'm new to views and cck (just installed both today), but maybe a possible workaround to the range selection on a cck field is to create a computed field which simply has the same value as the field you want to place the range filter on. Then you would have two fields with the same value, avoiding the need to place two filters on the same field. You could filter the original field for the "less than", and the duplicate computed field for the "greater than". I think you would need to specify in cck that the computed field be stored in the database in order for this to work. Haven't tried it yet because for some reason the only filter operators that show up for me for the CCK integer fields I'm working with are "is one of", and "is none of". If someone could explain how to get the <, >, <=, >= operators to show up, I'd gladly test my idea for the range selection and report back.
Comment #13
Budrick commentedMy workaround:
I have a CCK type "car" with "year of production" field.
I need to select cars produced in a range of years.
In my view ive added two filters for year: one is "equal or greater then 1950" and the other "equal or less then 2030", so all the cars fits the range.
Then ive added this function to my module:
Now, if I point my browser to the url "http://localhost/?q=cars/all/2001-2003" the hook in my module will just substitute the values in filters with values from url.
Mention that you should NOT add "year" to arguments in view admin form. It wont work because views module tries to process "2001-2003" as integer argument.
Comment #14
tom friedhof commentedThanks Budrick, that's an awesome workaround. Thanks for sharing that with us all, as I've been wondering how to accomplish this for a while. Thank you.
Comment #15
lias commentedWhat module are you referring to? Views? Is that where you added the function?
Comment #16
Budrick commentedMy custom module named "usacar";
Comment #17
q_man commentedIf you haven't found it yet, try looking at this patch. Hopefully to be included in core soon...
http://drupal.org/node/151989
Comment #18
Budrick commentedSee also
Comment #19
kreativalab commentedany solution to search one user by a range of values (integer i mean)...age...
Comment #20
esmerel commentedNo commits are being made to the 5.x branch at this point.