From 0b380ad323d339c8ab6b4df2041392ef617796d4 Mon Sep 17 00:00:00 2001 From: Mottie Date: Mon, 30 Jun 2014 23:07:12 -0500 Subject: [PATCH] Filter: add filter_searchFiltered option to allow disabling the search of already filtered rows --- docs/index.html | 41 ++++++++++++++++++++++++++++++++ js/jquery.tablesorter.widgets.js | 37 +++++++++++++++------------- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/docs/index.html b/docs/index.html index 4ca427c4..e83cf2ef 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1617,6 +1617,8 @@ $(function(){ filter_saveFilters : false, // typing delay in milliseconds before starting a search. filter_searchDelay : 300, + // allow searching through already filtered rows in special circumstances; will speed up searching in large tables if true + filter_searchFiltered: true, // include a function to return an array of values to be added to the column filter select filter_selectSource : null, // if true, filter start from the beginning of the cell contents. @@ -2406,6 +2408,45 @@ $('table').trigger('search', false); + + + Boolean + true + + Filter widget: Set this option to allow searching through already filtered rows (in special conditions); this will speed up searching in large tables (v2.17.4). +
+
+ To better explain this, lets do it by example. Lets say you have a column of color names and you enter "light" and results like "light blue" and "light grey" show up.
+
+ When you press the space bar, a space is added, and instead of searching though all of the colors again, the filter widget only searches through the already filtered results that started with "light". This can substantially speed up searching, especially in large tables.
+
+ But, there are some special circumstances which would make this method return incorrect results. So, this option was added to allow you to disable this feature in case one of these following conditions doesn't cover your need; but still, please report any issues!
+
+ The search through filtered results only occurs if the following conditions are met: + + If the debug option is set to true, then a message will appear while filtering stating the specific number of rows, or "all" rows, that are being searched.
+
+ Use the filter_searchFiltered option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_searchFiltered : false
+    }
+  });
+});
+ + + + Function diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js index eb484eb1..b2a105a9 100644 --- a/js/jquery.tablesorter.widgets.js +++ b/js/jquery.tablesorter.widgets.js @@ -364,6 +364,7 @@ ts.addWidget({ filter_reset : null, // jQuery selector string of an element used to reset the filters filter_saveFilters : false, // Use the $.tablesorter.storage utility to save the most recent filters filter_searchDelay : 300, // typing delay in milliseconds before starting a search + filter_searchFiltered: true, // allow searching through already filtered rows in special circumstances; will speed up searching in large tables if true filter_selectSource : null, // include a function to return an array of values to be added to the column filter select filter_startsWith : false, // if true, filter start from the beginning of the cell contents filter_useParsedData : false, // filter all data using parsed content @@ -944,24 +945,26 @@ ts.filter = { $rows = $rows.not('.' + c.cssChildRow); len = $rows.length; // optimize searching only through already filtered rows - see #313 - searchFiltered = true; + searchFiltered = wo.filter_searchFiltered; lastSearch = c.lastSearch || c.$table.data('lastSearch') || []; - for (indx = 0; indx < columnIndex; indx++) { - val = filters[indx] || ''; - // break out of loop if we've already determined not to search filtered rows - if (!searchFiltered) { indx = columnIndex; } - // search already filtered rows if... - searchFiltered = searchFiltered && lastSearch.length && - // there are no changes from beginning of filter - val.indexOf(lastSearch[indx] || '') === 0 && - // if there is NOT a logical "or", or range ("to" or "-") in the string - !regex.alreadyFiltered.test(val) && - // if we are not doing exact matches, using "|" (logical or) or not "!" - !/[=\"\|!]/.test(val) && - // don't search only filtered if the value is negative ('> -10' => '> -100' will ignore hidden rows) - !(/(>=?\s*-\d)/.test(val) || /(<=?\s*\d)/.test(val)) && - // if filtering using a select without a "filter-match" class (exact match) - fixes #593 - !( val !== '' && c.$filters && c.$filters.eq(indx).find('select').length && !c.$headers.filter('[data-column="' + indx + '"]:last').hasClass('filter-match') ); + if (searchFiltered) { + for (indx = 0; indx < columnIndex; indx++) { + val = filters[indx] || ''; + // break out of loop if we've already determined not to search filtered rows + if (!searchFiltered) { indx = columnIndex; } + // search already filtered rows if... + searchFiltered = searchFiltered && lastSearch.length && + // there are no changes from beginning of filter + val.indexOf(lastSearch[indx] || '') === 0 && + // if there is NOT a logical "or", or range ("to" or "-") in the string + !regex.alreadyFiltered.test(val) && + // if we are not doing exact matches, using "|" (logical or) or not "!" + !/[=\"\|!]/.test(val) && + // don't search only filtered if the value is negative ('> -10' => '> -100' will ignore hidden rows) + !(/(>=?\s*-\d)/.test(val) || /(<=?\s*\d)/.test(val)) && + // if filtering using a select without a "filter-match" class (exact match) - fixes #593 + !( val !== '' && c.$filters && c.$filters.eq(indx).find('select').length && !c.$headers.filter('[data-column="' + indx + '"]:last').hasClass('filter-match') ); + } } notFiltered = $rows.not('.' + wo.filter_filteredRow).length; // can't search when all rows are hidden - this happens when looking for exact matches