API method for exact match
API method for exact match
Loren Maxwell
Posts: 406Questions: 99Answers: 10
I kept doing this for each individual code when I decided to write an API method to adhere to the DRY principle.
Here's a new API method for an exact search:
$.fn.dataTable.Api.register( "exactMatch()", function ( searchTerm ) {
var regexTerm = "^" + $.fn.dataTable.util.escapeRegex( searchTerm ) + "$";
return this.search( regexTerm, true, false );
});
Use it like so:
var searchTerm = 'Georgia';
table.exactMatch( searchTerm ).draw();
For example this shows records for "Georgia" but not for "Georgia Tech" or "West Georgia".
Any thoughts on how to improve it would be more than welcomed!
This discussion has been closed.
Replies
Looks good. There are many posts asking for exact match searching. We can point them to this thread.
Kevin