Unexpected behaviours with regex searching, with workarounds

Unexpected behaviours with regex searching, with workarounds

CuCCuC Posts: 1Questions: 0Answers: 0

Hi folks,

New user here. Really appreciate the work that's gone into DataTables!

I ran across 2 unexpected (to me) behaviours with regex searching, and came up with workarounds that work for me, and that might be useful to others as well. If there are simpler solutions, that would be nice, too!

  • regex patterns can match across columns (I expected them to match only within a single cell)

Workaround: search columns individually

  • a (non-literal) column regex search can fail to match if global searches have not also been specified as regex. I think this is because the search function does "Filter the table using both the global filter and column based filtering" (from the comment in the source), and the column search is done as a global one, with the current settings for global search, not the one specified in the column search call.

To see this, go here: http://live.datatables.net/fasijehe/1/edit

The only change to the base example is the javascript, which adds the normal search box, and a simple custom handler to do regex searching on column 0.

Looking for any pattern that is not just literals will fail to match, even '.'. (Literal searches, like 'an" work fine.)

Workaround (for my use case, anyway): set the "search" option (for example, at initialization) to contain

regex:true

This makes global searches regex (including the implicit ones done with column searches). Since I don't need to do non-regex searches, this works for me. Not sure what happens if you need to mix regex and non-regex searches ...

Again, thanks for making DataTables available!

Cheers,

--Chris

Version 1.10.10

Browsers: Safari 9.0.1, Firefox 44.0.2 (OS X)

This discussion has been closed.