Skip to content
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

Closed
satacoy opened this issue Oct 29, 2012 · 9 comments
Closed

Using "And" / "Or" with filters #166

satacoy opened this issue Oct 29, 2012 · 9 comments

Comments

@satacoy
Copy link

satacoy commented Oct 29, 2012

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.

@Mottie
Copy link
Owner

Mottie commented Oct 29, 2012

I had something like this planned for the quick search widget, but I can look into including it with the current filter widget.

@satacoy
Copy link
Author

satacoy commented Oct 29, 2012

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

@mitcrellim
Copy link

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.

@satacoy
Copy link
Author

satacoy commented Oct 29, 2012

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.

@mitcrellim
Copy link

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.

@matzhu
Copy link

matzhu commented Nov 7, 2012

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
result: finds range between 10 and 90

@satacoy
Copy link
Author

satacoy commented Nov 7, 2012

Great! I'll give this a shot. Thanks for the suggestion!

@satacoy
Copy link
Author

satacoy commented Nov 7, 2012

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!

@Mottie
Copy link
Owner

Mottie commented Nov 8, 2012

@satacoy That may not be a good idea since - also applies to negative numbers.

@Mottie Mottie closed this as completed in 5eafcf7 Feb 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants