Regex not working with DataTables
Regex not working with DataTables
Hello,
I'm hoping there may be someone that can help me figure out how to use regex with DataTables.
So, I have a column that I'm looking to search. This column holds multiple different values, including 'Services' and 'Industry'. I'm looking to specifically search/filter for 'Services' and 'Industry'.
These are the attempted regex configurations:
regex_services = "/^(?=.(Services|Industry)).$/gm";
regex_services = "/\b(?:Services|Industry)\b/gi";
This is the search code I'm using
table_services.columns(1).search(regex_services, true, false, false).draw();
The issue is that there's no data returned in the table.
Any help is much appreciated! Thank you.
PS: the configuration below works, but only to search/filter for 'Services' and not 'Industry' as well.
table_services.columns(1).search('Services').draw();
Answers
See if this example helps:
http://live.datatables.net/giwefeye/1/edit
Kevin
Thank you Kevin. Your example works as I wish my code would. I've tried replicating it, but my table still comes up empty (no data shows up). Very strange. I've even updated the DT code to the latest version.
Wonder if perhaps my DT configuration may not be playing nice?
This is the full JS code I'm using:
You have
serverSide: true
. Your server script is responsible for performing the search. You will need to adjust your server script to support regex expressions. Are you using a Datatables supplied server side processing script?Or do you really need server side processing? How many rows of data do you have?
Kevin
Gotcha. Yes, I'm using the Datatables supplied server side processing script (the only custom changes were to the array below). Server side processing is required; I have thousands of rows currently, which will reach tens of thousands, maybe more in the future.
Do you happen to have any examples of how to implement regex server side?
Sorry I don't have any examples. Others may post some but these threads might give you some ideas:
https://datatables.net/forums/discussion/47717/exact-match-regex-serverside-true-and-editor
https://datatables.net/forums/discussion/61483/hints-for-a-better-search-experience-with-server-side-processing
You might be able to find other threads as well.
Kevin
Than you Kevin. Will look around! And check out the threads as well.