5

I am using jQuery DataTables plugin in my application. I am trying to search for a string that exactly matches the data in a column.

I checked the this topic and its solution is not working for my case. My search string is a regular expression with | symbols which might look like Logged In|Active|Not Active.

When the search string contains Active(Logged In|Active), records with Not Active are also showing up when I use the following search:

jQuery("#myTable").DataTable()
                .columns("#status")
                .search("^"+status+"$",true,false)
                .draw();
 

Any help is appreciated. Thanks in advance!

informatik01
  • 16,038
  • 10
  • 74
  • 104
rav
  • 247
  • 1
  • 6
  • 17

3 Answers3

9
jQuery("#myTable").DataTable()
                .columns("#status")
                .search("(^"+status+"$)",true,false)
                .draw();

This worked!

rav
  • 247
  • 1
  • 6
  • 17
0

Try below solution:
1. with smart search off (reference)

jQuery("#myTable").DataTable()
                .columns("#status")
                .search(status,false)
                .draw();


2.with double quotes (reference)

jQuery("#myTable").DataTable()
                    .columns("#status")
                    .search('"'+status+'"')
                    .draw();
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
  • Since we have multiple search words, we should be going for a regEx search. So the above solution would not work – rav May 16 '17 at 14:23
0

This worked for me:

 $('#yourTableID').DataTable({ 
  search: {
     regex: false,
     smart: false
  }
 })

You can find more information here: https://datatables.net/reference/option/search

Peter Catalin
  • 1,342
  • 1
  • 14
  • 22