API method for exact match

API method for exact match

Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9

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!

Replies

  • kthorngrenkthorngren Posts: 9,769Questions: 25Answers: 2,255

    Looks good. There are many posts asking for exact match searching. We can point them to this thread.

    Kevin

Sign In or Register to comment.