Exact Match Select Filter

Exact Match Select Filter

choggerchogger Posts: 15Questions: 4Answers: 0
edited August 2011 in General
Hey all :-)

I'm using the Multi Filter Select (http://www.datatables.net/release-datatables/examples/api/multi_filter_select.html) and have some Problems with my Car Column. It contains a Chevrolet Impala SS and a Chevrolet Impala SS Class B. If i choose the Impala SS i get the Impala SS Class B as well. I just want to get the exact Match. I think it has to do with Smart filtering and read about it but my knowledge isn't the best.

You can see my Problem on this Page:
http://www.chogger.de/?p=track_laps&trackid=20

Thank You

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited August 2011
    if you use regular expressions with your matching, you can use anchor elements to refer to the beginning ("^") or end ("$") of your value/line. "^Chevrolet Impala SS$" will only match if the whole value is exactly "Chevrolet Impala SS".

    The fnFilter call in the select.change event of the example code can take an argument specifying regular expression matching, which is by default false.
    [code]
    $('select', this).change( function () {
    oTable.fnFilter( "^"+$(this).val()+"$", i , true); // <--- add 3rd parameter "true" and add anchors
    } );
    [/code]


    http://www.datatables.net/ref#fnFilter
  • choggerchogger Posts: 15Questions: 4Answers: 0
    Thank You for the help, it solved the Problem but after i used this filter i'm not able to show all records again. See http://www.chogger.de/?p=track_laps&trackid=20 for better understanding of the problem ;)
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    ahh, you might want to change the code in the blank element to another regular expression meaning "select any":
  • choggerchogger Posts: 15Questions: 4Answers: 0
    Thank you again :)
    Works perfect
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Regular Expressions are one of the most important developments in text/language/pattern processing and it's a great thing that reg expressions are natively supported in javascript. Reg Exp is practically a language unto it self, but it's nothing to be intimidated by - totally worthwhile learning what you can about it. At least learn the rudiments.

    in the example above "." means match any character. "*" means match 0-or-more of the preceding character (or set). so combined ".*" means match any string of characters; it's a catch-all for matching, so you see this all the time.

    http://www.regular-expressions.info/reference.html
  • catequilcatequil Posts: 5Questions: 0Answers: 0
    I had this issue also with Active and Inactive. It would seem to me that the default should be exact match in this case. I would think it rare to none that anyone would not want an exact match when using select list for filtering. Does anyone else see the same as I see this? Is anyone using it to find things not exact match? If so please explain your reasoning for doing it this way as I am curious. Not that it is hard to make it work with exact match like above, but if no one is using the feature in a manner other than exact match I think that it would be wise to just default it that way. Just my two cents on this issue.
    Thanks :)
This discussion has been closed.