Exact column matching using individual column filtering with select menus

Exact column matching using individual column filtering with select menus

tr333tr333 Posts: 12Questions: 0Answers: 0
edited March 2012 in DataTables 1.9
I'm using invidual column filtering with select menus from http://datatables.net/examples/api/multi_filter_select.html, but I've run into a problem. If I have a column with values "Test 1", "Test 2", etc. up to "Test 12", then when I select "Test 1" in the select menu it will filter for "Test 1", "Test 10", "Test 11", "Test 12".

Is there any way to tell DataTables to do an exact match when filtering on a particular column? I suppose I could place the value inside "^$" and set the regex filter mode, but then I would have to escape all the regex reserved characters that might appear in the value. Is there any easier way to do it?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You are correct, regex is the way to do that. You would want to do something like: fnFilter( "^"+this.value+"$", column, true, false ); to make an exact match, so yes, you would also want to escape regex special values (note the third parameter, true, tells DataTables you are giving it a regex string, and the forth parameter tells it not to do its own "smart filtering").

    Allan
  • tr333tr333 Posts: 12Questions: 0Answers: 0
    edited March 2012
    Thanks Allan. I used the XRegExp library (http://xregexp.com/) to do regex escaping on the value, to prevent things like '(' characters getting caught up in the regex string.

    [code]fnFilter( '^' + XRegExp.escape(this.value) + '$', column, true, false );[/code]
This discussion has been closed.