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

Filter widget: Add support for exact match #80

Closed
riker09 opened this issue May 29, 2012 · 8 comments
Closed

Filter widget: Add support for exact match #80

riker09 opened this issue May 29, 2012 · 8 comments

Comments

@riker09
Copy link
Contributor

riker09 commented May 29, 2012

I have a table with values like

  • value 1
  • value 2
  • value 11
  • value 24

If I filter for example "value 2" the filter widget shows rows 2 and 4. If possible please add an option that makes it possible to do exact matching (the example above should only show row 2).

@Mottie
Copy link
Owner

Mottie commented May 29, 2012

I have another request to support regex in issue #79, so I have an idea...

What if you enter some kind of flag to indicate how to treat the string. These are just ideas, so any feedback would be appreciated.

  • x - Find all matches of "x"; within a string or alone, so it matches x, codex1 and Xavier (if filter_ignoreCase is true). This is the normal behavior.
  • "x" - Find exactly what's inside the quotes, so "x" matches only x but not codex1; or maybe just end with a quote, like x" so the first quote doesn't show an empty filter result during typing.
  • x*x - Find a word starting and ending with x with any length of characters in-between, so xxx will be found as well as xerox
  • x?x - Find a word starting and ending with x with only one character in-between, so xxx will be found, but not xerox

I'm not sure if I should make it support straight regex since most users may not understand how to use it.

@nschneid
Copy link

I don't know if this plugin has a certain kind of end-user in mind; maybe it would be easiest to allow a matches callback function to be specified (taking the query string and each candidate match as arguments, returning true or false), and leave it up to the application to specify a front-end interface for choosing the type of matching?

For my application I was hoping to support case-sensitive regular expression matching if the query is delimited by slashes, and the current behavior otherwise.

@riker09
Copy link
Contributor Author

riker09 commented May 30, 2012

I really like the idea to be able to write my own callback function. I think this would be the most flexible way to handle custom filter needs.

@Mottie
Copy link
Owner

Mottie commented Jun 1, 2012

Well I ended up adding all of the suggestions... crazy huh?

I split the filter widget demo into two and made a basic filter widget demo where you can type in ? and * as described above. Or add a quote " at the end of the filter to make it an exact match.

The second demo shows how to use the new filter_functions option which allows you to add custom filter functions, or add a select dropdown that is either automatically populated or populated with custom functions.

Enjoy!

@nschneid
Copy link

nschneid commented Jun 2, 2012

Awesome, thanks!

@riker09
Copy link
Contributor Author

riker09 commented Jun 4, 2012

Nice work! I really like the new filter function.

Unfortunately the tablesorter.widgets.min.js file breaks some other function in my project. I'm using jqplot to draw some graphs. When the widget file is present in the html's head and I use the function to generate an image from the plotted graph (jQuery('#graph_id').jqplotToImageElem()) I'll get an error:
Uncaught Error: Syntax error, unrecognized expression: ] in jQuery. I don't know if it is related but I had to rename the methods in the widget file from AddWidget to addWidget (lowercase). Otherwise I was getting the error Uncaught TypeError: Object [object Object] has no method 'AddWidget'

For now I just remove the widget.js file from the relevant pages, fortunately I don't need both functions on the same page (yet).

@Mottie
Copy link
Owner

Mottie commented Jun 4, 2012

Hmm, the tablesorter function isn't AddWidget, it is camel-cased properly as addWidget. Where did you see it with a capitalized "A"?

Ahhh never mind.. that is a mistake on my part when formatting the minified version... I'll fix it.

@Mottie
Copy link
Owner

Mottie commented Jun 4, 2012

Fixed! Sorry!

@Mottie Mottie closed this as completed Jun 10, 2012
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

3 participants