Fuzzy searching is used in search engines and databases to perform searches that will match results that are not necessarily exactly the same as the search term. This allows spelling mistakes and typos to be accounted for. It also allows small changes in dialect not to affect search results. A commonly used example is for surname searching. "Smith" and "Smythe" are pronounced the same way, but using conventional searching typing "Smith" would not return "Smythe".
This plug-in adds fuzzy search functionality to DataTables. It does this through a combination of exact matching and the Damerau-Levenshtein algorithm. There are three initialisation options that are associated with this plugin.
fuzzySearch.toggleSmart
allows the searching to be changed from exact matching to fuzzy searching.fuzzySearch.rankColumn
allows the % match to be set in a column within the Datatable. Some examples of use cases could be to display the value
to the user. or to hide the column and order based on it - as a search engine would.fuzzySearch.threshold
allows the value of similarity that is required from the Damerau-Levenshtein function to display the row to be
changed.This example shows how fuzzySearch integrates with stateSave
. The search mode, the value within the search box and the search results are restored
as they were on reload. To display all of the stateSave
functionality, fuzzySearch.toggleSmart
and fuzzySearch.rankColumn
are set to true and 6 respectively.
Name | Position | Office | Age | Start date | Salary | Similarity |
---|---|---|---|---|---|---|
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 | |
Angelica Ramos | Chief Executive Officer (CEO) | London | 47 | 2009/10/09 | $1,200,000 | |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 | |
Bradley Greer | Software Engineer | London | 41 | 2012/10/13 | $132,000 | |
Brenden Wagner | Software Engineer | San Francisco | 28 | 2011/06/07 | $206,850 | |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 | |
Bruno Nash | Software Engineer | London | 38 | 2011/05/03 | $163,500 | |
Caesar Vance | Pre-Sales Support | New York | 21 | 2011/12/12 | $106,450 | |
Cara Stevens | Sales Assistant | New York | 46 | 2011/12/06 | $145,600 | |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 | |
Name | Position | Office | Age | Start date | Salary | Similarity |
The Javascript shown below is used to initialise the table shown in this example:
$(document).ready(function() {
var table = $('#example').DataTable({
fuzzySearch: {
rankColumn: 6,
toggleSmart: true
},
stateSave: true
});
} );