-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using "And" / "Or" with filters #166
Comments
I had something like this planned for the quick search widget, but I can look into including it with the current filter widget. |
Great, thanks! I took a look at how other table filters work (PicNet Table Filter, for example), they seem to imply an "And" for each space separated filter term by default. This seems pretty intuitive from a user's point of view. I took a look at your code to see if I could contribute, it's a wee bit too dense for my brain! :-) |
This works for me in a type in filter field to OR things together. I have not tried to look at the code to see how it works. But I use the pipe | character for 'OR'. For example, I have a column with values of 'Not Started', 'In Progress' and 'Live' (maybe some other values, to). I want to get all rows of 'Not Started' and 'In Progress' and if I type in 'In|not' then I get just rows with those two values in that column. Is this a lucky fluke? I am not sure, but it works great for me. |
You're right, that does work for OR at least for text fields. I can't seem to get it to work with the >= style filters. And I tried "&" hoping it would do an AND operator, but no luck. Thanks for the tip, that gets me a bit closer, although having an AND that works with >=,<= would get me there. |
I am pretty sure you will have to write some custom code to get it to work like you want. I messed with it a little but then just settled with a drop down of the expected type of filtering folks would want on my numeric column. |
add this at line 421 of jquery.tablesorter.widgets.js ( tableSorter 2.4+ widgets - updated 10/17/2012 ) // Look for operators &
} else if (/[&]/.test(val)){
rg = isNaN(xi) ? $.tablesorter.formatFloat(xi.replace(reg[5], ''), table) : $.tablesorter.formatFloat(xi, table);
var vals = val.split('&');
var min = $.tablesorter.formatFloat(vals[0], table)
var max = $.tablesorter.formatFloat(vals[1], table)
ff = rg >= min && rg <= max ? true : false; usage: 10&90 |
Great! I'll give this a shot. Thanks for the suggestion! |
I made a few changes to allow this to work with specially formatted fields a bit. I also changed it to use the "-" character instead, since that (at least to me) implies a range operator a bit more than an "&". // Look for operators "-", meaning "Between"
} else if (/[-]/.test(val)){
rg = isNaN(xi) ? $.tablesorter.formatFloat(xi.replace(reg[5], ''), table) : $.tablesorter.formatFloat(xi, table);
var vals = val.split('-');
var min = $.tablesorter.formatFloat(vals[0].replace(reg[5], ''), table)
var max = $.tablesorter.formatFloat(vals[1].replace(reg[5], ''), table)
ff = rg >= min && rg <= max ? true : false; Thanks again for the help! |
@satacoy That may not be a good idea since |
Is there a way to specify two fields in a filter box, and have them "ANDed" or "ORed"? I don't see any hints of that by looking through the source, rather than using regular expressions. I'm hoping there's a user friendly way to get this done.
The same applies to the >= and <= operators, it'd be great to specify that a number is between two arbitrary values, something like ">=100 AND <= 200". I realize I could set up predetermined ranges, and let the user select from them, but it'd be much nicer to allow the user to specify the exact range they're interested in.
The text was updated successfully, but these errors were encountered: