mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Add filter_saveFilters option. See #388
This commit is contained in:
parent
3fede9fe7e
commit
af0a142948
@ -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 @@ $(function(){
|
||||
<h3><a href="#">Notes</a></h3>
|
||||
<div>
|
||||
<ul>
|
||||
<li>Added & set <code>filter_saveFilters</code> to <code>true</code> (default is <code>false</code>) in this demo (<span class="version">v2.14</span>).</li>
|
||||
<li>Hover over the grey bar below the table header to open the filter row. Disable this by setting <code>filter_hideFilters</code> option to <code>false</code>.</li>
|
||||
<li>This widget uses jQuery's <code>.nextUntil()</code> function which is only available is jQuery version 1.4+.</li>
|
||||
<li>This widget does work with tablesorter v2.0.5.</li>
|
||||
@ -239,6 +243,7 @@ $(function(){
|
||||
<li><code>filter_liveSearch : true</code> - 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.</li>
|
||||
<li><code>filter_onlyAvail : 'filter-onlyAvail'</code> - a header with a select dropdown & this class name will only show available (visible) options within that drop down.</li>
|
||||
<li><code>filter_reset : null</code> - jQuery selector string of an element used to reset the filters.</li>
|
||||
<li><code>filter_saveFilters : false</code> - Uses the <code>$.tablesorter.storage</code> utility to save the most recent filters.</li>
|
||||
<li><code>filter_searchDelay : 300</code> - typing delay in milliseconds before starting a search.</li>
|
||||
<li><code>filter_serversideFiltering : false</code> - if true, filter will be done server-side. The client-side filtering will be disabled, but the ui and events will still be used.</li>
|
||||
<li><code>filter_startsWith : false</code> - if true, filter start from the beginning of the cell contents.</li>
|
||||
@ -339,8 +344,8 @@ $(".search").bind('search keyup', function (e) {
|
||||
<hr>
|
||||
|
||||
<div id="demo">
|
||||
<button type="button" data-filter-column="5" data-filter-text="2?%">Saved Search</button> (search the Discount column for "2?%")<br>
|
||||
<button type="button" class="reset">Reset Search</button> <!-- targeted by the "filter_reset" option -->
|
||||
Search <button type="button" data-filter-column="5" data-filter-text="2?%">2?%</button> in the Discount column<br>
|
||||
<button type="button" class="reset">Reset</button> <!-- targeted by the "filter_reset" option -->
|
||||
|
||||
<table class="tablesorter">
|
||||
<thead>
|
||||
|
@ -1437,6 +1437,8 @@ $(function(){
|
||||
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 @@ $(function(){
|
||||
<td><a href="example-widget-filter-custom.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="widget-filter-savefilters">
|
||||
<td><a href="#" class="permalink">filter_saveFilters</a></td>
|
||||
<td>Boolean</td>
|
||||
<td>false</td>
|
||||
<td>
|
||||
Filter widget: If the storage utility is available (included with <code>jquery.tablesorter.widgets.js</code>, the last applied filter is saved to storage (<span class="version">v2.14</span>).
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
Filters saved to local storage (or cookies) will over-ride any default filters within the header data-attribute (set by the <a href="#widget-filter-defaultattrib"><code>filter_defaultAttrib</code> option</a> and be available to the pager before any ajax calls are made.<br>
|
||||
<br>
|
||||
To bypass this behavior, clear out the saved filters as follows:
|
||||
<pre class="prettyprint lang-js">$.tablesorter.storage( $('table'), 'tablesorter-filters', '' );</pre>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="example-widget-filter-custom.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="widget-filter-searchdelay">
|
||||
<td><a href="#" class="permalink">filter_searchDelay</a></td>
|
||||
<td>Numeric</td>
|
||||
|
@ -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,19 +625,27 @@ 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;
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user