fnFilter with exact match breaks with + < > \ special characters, how to query?

fnFilter with exact match breaks with + < > \ special characters, how to query?

nroubalnroubal Posts: 2Questions: 0Answers: 0
edited February 2014 in General
I am using the Multi Filter select, but want to also an exact match in the inputs:
have a http://datatables.net/release-datatables/examples/api/multi_filter_select.html

[code]oTable.fnFilter( $(this).val(), i );[/code]

This works for non-exact matches.


I want an exact match, so if A is selected, only the first row would display. If A + is selected, only the third row, if B is selected, only the second row, and so on. I am using the datatables plugin.

Example Data:
A
B
A +
A + B
A + B

I have altered the query to include a RegEx with RegEx enabled, and disabled the Smart Filter, which is working perfect for every input as expected.

This works perfectly, except certain values will break the RegEx:

[code]oTable.fnFilter("^"+$(this).val()+"$", i, true);[/code]

The characters +, <, >, \ break my exact query, but are allowed in the original query... but they do not do an exact match.

Any suggestions for a character-proof exact match filter?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It sounds like you need to escape the regular expression characters... This is how DataTables does it internally, which you could copy the function of: https://github.com/DataTables/DataTablesSrc/blob/master/js/core/core.filter.js#L280 (the regex is defined in the core.internal.js file).

    Allan
  • nroubalnroubal Posts: 2Questions: 0Answers: 0
    The method of copying the RegEx worked well, however the full _fnEscapeRegex function was found in the core.filter.js instead. < > characters were not in the function so I added these and it is working now.
This discussion has been closed.