Perform exact match when searching

2019-09-25 12:20发布

On my site I am using the plugin wpDataTables based on jQuery DataTables.

My first column in the price list table contains values - AUR, D, DH, etc. Table is programmed to show only first 6 results out of many.

Here is the problem: If I want user to find value D and user types in the search field D, you'll get a list with values DH.

It happens because by default jQuery DataTables plugin finds records that contain value D (such as DH, etc), but I want it to perform exact match.

Please see Excel spreadsheet containing all records for reference.

1条回答
成全新的幸福
2楼-- · 2019-09-25 12:53

You need to follow this documentation and end up with something like this:

table.column( 1 ).search( '^My exact match$', true, false );

You can also use quotes when you input or add them before passing to the search function:

 table.search( '"My exact match"' );

Documentation: https://datatables.net/reference/api/column().search()

查看更多
登录 后发表回答