Reputation: 549
How is one supposed to use regular expressions in the searchCols option of Datatables 1.10 and above? It filters fine for normal strings, but does not work for regular expressions, as far as I can tell.
Here is some code (full example at http://live.datatables.net/bahejesi/1/edit):
$(document).ready(function() {
$('#example').dataTable( {
"ajax": "/ssp/server_processing.php",
searchCols: [
null,
null,
null,
{ search: "(London|New York)", "escapeRegex": false },
null,
null
]
} );
} );
Eventually, what I want to achieve is to filter my table based on input from the query string (e.g., id = a OR b, id <= c). (Not sure the latter part can be achieved with RegExp.)
Another option would be the API filter() function. But I don't know how to integrate that with the example code above.
Upvotes: 0
Views: 2887
Reputation: 549
Ok, the documentation on searchCols
is not very clear. Each element of searchCols
behaves just as search
itself does. So, adding "regex": true
as an option does the job. Not sure what "escapeRegex": false
does in this case. It does not seem to have any effect.
$(document).ready(function() {
$('#example').dataTable( {
"ajax": "/ssp/server_processing.php",
searchCols: [
null,
null,
null,
{ "search": "^S", "regex": true },
null,
null
]
} );
} );
Upvotes: 3