diff --git a/docs/example-widget-filter.html b/docs/example-widget-filter.html index 7d6dd3b92..6b4b48181 100644 --- a/docs/example-widget-filter.html +++ b/docs/example-widget-filter.html @@ -86,6 +86,9 @@ // jQuery selector string of an element used to reset the filters filter_reset : 'button.reset', + // Use the $.tablesorter.storage utility to save the most recent filters (default setting is false) + filter_saveFilters : true, + // Delay in milliseconds before the filter widget starts searching; This option prevents searching for // every character while typing and should make searching large tables faster. filter_searchDelay : 300, @@ -195,6 +198,7 @@
filter_saveFilters
to true
(default is false
) in this demo (v2.14).filter_hideFilters
option to false
..nextUntil()
function which is only available is jQuery version 1.4+.widgetOptionsfilter_liveSearch : true
- if true, search column content while the user types (with a delay). If false, the user must press enter to start the search. If set to a number, when the length of the input text reaches this minimum length, a search will initiate.
filter_onlyAvail : 'filter-onlyAvail'
- a header with a select dropdown & this class name will only show available (visible) options within that drop down.
filter_reset : null
- jQuery selector string of an element used to reset the filters.
+ filter_saveFilters : false
- Uses the $.tablesorter.storage
utility to save the most recent filters.
filter_searchDelay : 300
- typing delay in milliseconds before starting a search.
filter_serversideFiltering : false
- if true, filter will be done server-side. The client-side filtering will be disabled, but the ui and events will still be used.
filter_startsWith : false
- if true, filter start from the beginning of the cell contents.
@@ -339,8 +344,8 @@ Demo
- (search the Discount column for "2?%")
-
+ Search in the Discount column
+
diff --git a/docs/index.html b/docs/index.html
index 4d64b8d19..cffa33b20 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1437,6 +1437,8 @@ Configuration
filter_onlyAvail : 'filter-onlyAvail',
// jQuery selector string of an element used to reset the filters.
filter_reset : null,
+ // Use the $.tablesorter.storage utility to save the most recent filters
+ filter_saveFilters : false,
// typing delay in milliseconds before starting a search.
filter_searchDelay : 300,
// if true, filter start from the beginning of the cell contents.
@@ -2088,6 +2090,23 @@ Comparison example
Example
+
+ filter_saveFilters
+ Boolean
+ false
+
+ Filter widget: If the storage utility is available (included with jquery.tablesorter.widgets.js
, the last applied filter is saved to storage (v2.14).
+
+
+ Filters saved to local storage (or cookies) will over-ride any default filters within the header data-attribute (set by the filter_defaultAttrib
option and be available to the pager before any ajax calls are made.
+
+ To bypass this behavior, clear out the saved filters as follows:
+ $.tablesorter.storage( $('table'), 'tablesorter-filters', '' );
+
+
+ Example
+
+
filter_searchDelay
Numeric
diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js
index bfb926c2c..31c7b8a30 100644
--- a/js/jquery.tablesorter.widgets.js
+++ b/js/jquery.tablesorter.widgets.js
@@ -348,6 +348,7 @@ ts.addWidget({
filter_liveSearch : true, // if true, search column content while the user types (with a delay)
filter_onlyAvail : 'filter-onlyAvail', // a header with a select dropdown & this class name will only show available (visible) options within the drop down
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_startsWith : false, // if true, filter start from the beginning of the cell contents
filter_useParsedData : false, // filter all data using parsed content
@@ -624,18 +625,26 @@ ts.filter = {
if (filters.length) {
ts.setFilters(table, filters, true);
}
+ ts.filter.checkFilters(table, filters);
});
// filter widget initialized
wo.filter_Initialized = true;
c.$table.trigger('filterInit');
- ts.filter.checkFilters(table);
},
setDefaults: function(table, c, wo) {
var indx,
filters = [],
columns = c.columns;
- for (indx = 0; indx < columns; indx++) {
- filters[indx] = c.$headers.filter('[data-column="' + indx + '"]:last').attr(wo.filter_defaultAttrib) || filters[indx];
+ if (wo.filter_saveFilters && ts.storage) {
+ filters = ts.storage( table, 'tablesorter-filters' ) || [];
+ // make sure we're not just saving an empty array
+ if (filters.join('') === '') { filters = []; }
+ }
+ // if not filters saved, then check default settings
+ if (!filters.length) {
+ for (indx = 0; indx < columns; indx++) {
+ filters[indx] = c.$headers.filter('[data-column="' + indx + '"]:last').attr(wo.filter_defaultAttrib) || filters[indx];
+ }
}
$(table).data('lastSearch', filters);
return filters;
@@ -915,6 +924,9 @@ ts.filter = {
c.lastCombinedFilter = combinedFilters; // save last search
c.lastSearch = filters;
c.$table.data('lastSearch', filters);
+ if (wo.filter_saveFilters && ts.storage) {
+ ts.storage( table, 'tablesorter-filters', filters );
+ }
if (c.debug) {
ts.benchmark("Completed filter widget search", time);
}