From 3195490f514b4e9f35466b53c504745a66329190 Mon Sep 17 00:00:00 2001 From: SandyDatatables Date: Fri, 13 Aug 2021 10:35:33 +0000 Subject: [PATCH] dev: Update to use the new search.return initialisation option Jira Issue DD-2073 --- .../fuzzySearch/dataTables.fuzzySearch.js | 13 +++++++------ features/fuzzySearch/index.html | 3 +-- features/fuzzySearch/rankColumn.html | 5 +---- features/fuzzySearch/returnSearch.html | 19 +++++++------------ features/fuzzySearch/stateSaving.html | 5 +---- features/fuzzySearch/threshold.html | 3 +-- features/fuzzySearch/toggleSmart.html | 3 +-- 7 files changed, 19 insertions(+), 32 deletions(-) diff --git a/features/fuzzySearch/dataTables.fuzzySearch.js b/features/fuzzySearch/dataTables.fuzzySearch.js index ca80a04..fd9555d 100644 --- a/features/fuzzySearch/dataTables.fuzzySearch.js +++ b/features/fuzzySearch/dataTables.fuzzySearch.js @@ -199,10 +199,11 @@ $(document).on('init.dt', function(e, settings) { var api = new $.fn.dataTable.Api(settings); - var initial = api.init().fuzzySearch; + var initial = api.init(); + var initialFuzzy = initial.fuzzySearch; // If this is not set then fuzzy searching is not enabled on the table so return. - if(!initial) { + if(!initialFuzzy) { return; } @@ -232,7 +233,7 @@ // Only going to set the toggle if it is enabled var toggle, tooltip, exact, fuzzy, label; - if(initial.toggleSmart) { + if(initialFuzzy.toggleSmart) { toggle =$('') .insertAfter(input) .css({ @@ -300,7 +301,7 @@ // The function that we want to run on search var triggerSearchFunction = function(event){ // If the search is only to be triggered on return wait for that - if ((event.type === 'input' && !initial.returnSearch) || event.key === "Enter") { + if ((event.type === 'input' && !initial.search.return) || event.key === "Enter") { // If the toggle is set and isn't checkd then perform a normal search if(toggle && !toggle.attr('blurred')) { api.rows().iterator('row', function(settings, rowIdx) { @@ -324,7 +325,7 @@ // For each row call the fuzzy search function to get result api.rows().iterator('row', function(settings, rowIdx) { - settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initial) + settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy) }); fromPlugin = true; @@ -352,7 +353,7 @@ // For each row call the fuzzy search function to get result api.rows().iterator('row', function(settings, rowIdx) { - settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initial) + settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(fuzzySearchVal, settings.aoData[rowIdx]._aFilterData, initialFuzzy) }); // triggerSearchFunction({key: 'Enter'}); return this; diff --git a/features/fuzzySearch/index.html b/features/fuzzySearch/index.html index e76d1f7..567c5c7 100644 --- a/features/fuzzySearch/index.html +++ b/features/fuzzySearch/index.html @@ -71,7 +71,7 @@ $(document).ready(function() { 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 four initialisation options that are associated with this + "https://github.com/tad-lispy/node-damerau-levenshtein">Damerau-Levenshtein algorithm. There are three initialisation options that are associated with this plugin.

diff --git a/features/fuzzySearch/rankColumn.html b/features/fuzzySearch/rankColumn.html index bf5b0cc..b0eb69a 100644 --- a/features/fuzzySearch/rankColumn.html +++ b/features/fuzzySearch/rankColumn.html @@ -73,7 +73,7 @@ $(document).ready(function() { 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 four initialisation options that are associated with this + "https://github.com/tad-lispy/node-damerau-levenshtein">Damerau-Levenshtein algorithm. There are three initialisation options that are associated with this plugin.

This example demonstrates the use of the fuzzySearch.rankColumn initialisation option. The default value for this option is undefined which will lead to the similarity not being displayed in any column. In this example fuzzySearch.rankColumn is set to 6 which is the column on the far right of @@ -631,13 +630,11 @@ $(document).ready(function() {

The Javascript shown below is used to initialise the table shown in this example:

$(document).ready(function() { - $(document).ready(function() { var table = $('#example').DataTable({ fuzzySearch: { rankColumn: 6 } }); - } ); } ); diff --git a/features/fuzzySearch/returnSearch.html b/features/fuzzySearch/returnSearch.html index c2f3a06..b51ed7c 100644 --- a/features/fuzzySearch/returnSearch.html +++ b/features/fuzzySearch/returnSearch.html @@ -55,9 +55,8 @@ $(document).ready(function() { var table = $('#example').DataTable({ - fuzzySearch: { - returnSearch: true - } + fuzzySearch: true, + search:{return: true} }); } ); @@ -73,7 +72,7 @@ $(document).ready(function() { 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 four initialisation options that are associated with this + "https://github.com/tad-lispy/node-damerau-levenshtein">Damerau-Levenshtein algorithm. There are three initialisation options that are associated with this plugin.

-

This example demonstrates the use of the fuzzySearch.returnSearch initialisation option. The default value for this option is undefined which lead to the search - results being updated on every keypress. In this example fuzzySearch.returnSearch is set to true, meaning that the search results displayed within the table will +

This example demonstrates how fuzzy searching can make use of the search.return initialisation option which is new in DataTables version 1.11. The default value for this option is false which lead to the search + results being updated on every keypress. In this example search.return is set to true, meaning that the search results displayed within the table will only be updated when the enter key is pressed.

@@ -570,13 +568,10 @@ $(document).ready(function() {

The Javascript shown below is used to initialise the table shown in this example:

$(document).ready(function() { - $(document).ready(function() { var table = $('#example').DataTable({ - fuzzySearch: { - returnSearch: true - } + fuzzySearch: true, + search:{return: true} }); - } ); } ); diff --git a/features/fuzzySearch/stateSaving.html b/features/fuzzySearch/stateSaving.html index a98752d..3b05372 100644 --- a/features/fuzzySearch/stateSaving.html +++ b/features/fuzzySearch/stateSaving.html @@ -75,7 +75,7 @@ $(document).ready(function() { 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 four initialisation options that are associated with this + "https://github.com/tad-lispy/node-damerau-levenshtein">Damerau-Levenshtein algorithm. There are three initialisation options that are associated with this plugin.

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 @@ -631,7 +630,6 @@ $(document).ready(function() {

The Javascript shown below is used to initialise the table shown in this example:

$(document).ready(function() { - $(document).ready(function() { var table = $('#example').DataTable({ fuzzySearch: { rankColumn: 6, @@ -639,7 +637,6 @@ $(document).ready(function() { }, stateSave: true }); - } ); } ); diff --git a/features/fuzzySearch/threshold.html b/features/fuzzySearch/threshold.html index b3ed0fb..8b06c21 100644 --- a/features/fuzzySearch/threshold.html +++ b/features/fuzzySearch/threshold.html @@ -74,7 +74,7 @@ $(document).ready(function() { 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 four initialisation options that are associated with this + "https://github.com/tad-lispy/node-damerau-levenshtein">Damerau-Levenshtein algorithm. There are three initialisation options that are associated with this plugin.

This example demonstrates the use of the fuzzySearch.threshold initialisation option. The default value for this option is 0.5. This value is used to compare against the Damerau-Levenshtein similarity metric which is calculated by dividing the number of changes needed to make the words the same, by the length of diff --git a/features/fuzzySearch/toggleSmart.html b/features/fuzzySearch/toggleSmart.html index 4dc86a7..0680b3a 100644 --- a/features/fuzzySearch/toggleSmart.html +++ b/features/fuzzySearch/toggleSmart.html @@ -74,7 +74,7 @@ $(document).ready(function() { 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 four initialisation options that are associated with this + "https://github.com/tad-lispy/node-damerau-levenshtein">Damerau-Levenshtein algorithm. There are three initialisation options that are associated with this plugin.

This example demonstrates the use of the fuzzySearch.toggleSmart initialisation option. The default value for this option is undefined which leads to fuzzy searching being used all the time if the fuzzySearch option is declared in the initialisation options. In this example fuzzySearch.toggleSmart