JQuery DataTable - Search for exact match

五迷三道 提交于 2019-12-25 16:53:44

问题


I have looked at several other responses and tried them all but nothing works. I have the following in my table:

Date        Severity
2016-04-24  Not Critical    
2016-04-24  Critical [what I need returned]
2017-01-09  Not Critical    
2017-09-13  Critical

I am trying to search for all rows where severity is Critical (value) for 2016 (year). So far I have:

table.search(  year + " " + value ).draw();

This returns both rows for 2016. How can I get it to return just the row that I need?


回答1:


You may need to enable and use regular expressions with search() and column().search() API methods.

Since you need to search two columns simultaneously, it may be better to combine two calls to column().search().

For example:

table
  .column(0).search('2016')
  .column(1).search('^Critical$', true, false)
  .draw();

where 0 and 1 are indexes of your date and severity columns.

See this example for code and demonstration.



来源:https://stackoverflow.com/questions/43991018/jquery-datatable-search-for-exact-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!