简体   繁体   English

DataTables列搜索完全匹配

[英]DataTables column search for exact match

I am using jQuery Datatables plugin in my application. 我在我的应用程序中使用jQuery Datatables插件。 I am trying to search for a string that exactly matches the data in a column. 我正在尝试搜索与列中的数据完全匹配的字符串。 I checked jQuery DataTables - Filter column by exact match which is not working for my case. 我检查了jQuery DataTables-按完全匹配过滤列,这不适用于我的情况。 My search string is a regular expression with | 我的搜索字符串是带|的正则表达式。 symbols which might look like Logged In|Active|Not Active . 可能看起来像“ 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: 当搜索字符串包含时,当我使用以下搜索时,还会显示具有“ Not Active ActiveLogged In|Active )记录:

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

Any help is appreciated. 任何帮助表示赞赏。 Thanks in advance! 提前致谢!

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

This worked! 这工作了!

Try below solution: 请尝试以下解决方案:
1. with smart search off ( reference ) 1.关闭智能搜索( 参考

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


2.with double quotes ( reference ) 2.双引号( 参考

jQuery("#myTable").DataTable()
                    .columns("#status")
                    .search('"'+status+'"')
                    .draw();

This worked for me: 这为我工作:

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

You can find more information here: https://datatables.net/reference/option/search 您可以在这里找到更多信息: https : //datatables.net/reference/option/search

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM