Perform exact match when searching

2019-09-25 13:04发布

问题:

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:

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()