Filter: add "filterAndSortReset" method. See #1361

This commit is contained in:
Rob Garrison 2017-04-02 07:40:24 -05:00
parent f006d8aa5f
commit 105bf11564
3 changed files with 30 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -5563,6 +5563,24 @@ $('table').trigger( 'search', [['', '', '', '', 'orange']] ); // find orange in
<td><a href="example-widget-filter.html">Example</a></td>
</tr>
<tr id="filterandsortreset">
<td><a href="#" class="permalink">filterAndSortReset</a></td>
<td>filter: Trigger the filter widget to reset the sort &amp; reset the search criteria (<span class="version">v2.28.7</span>).
<div class="collapsible">
<p>
This combination reset was added to prevent issues with the widgets not being updated after a combination of <a href="#filterreset"><code>filterReset</code></a> and <a href="#sortreset"><code>sortReset</code></a> due to internal timers preventing multiple widget applications in a row.
</p>
This method does not include a callback parameter similiar to the <code>sortReset</code> method.
<pre class="prettyprint lang-js">$(function() {
$('button').click(function(){
$('table').trigger('filterAndSortReset');
return false;
});</pre>
</div>
</td>
<td></td>
</tr>
<tr id="filterresetsaved">
<td><a href="#" class="permalink">filterResetSaved</a></td>
<td>filter: Make the filter widget reset any saved searches (<span class="version">v2.25.6</span>).

View File

@ -69,7 +69,7 @@
var tbodyIndex, $tbody,
$table = c.$table,
$tbodies = c.$tbodies,
events = 'addRows updateCell update updateRows updateComplete appendCache filterReset filterEnd search '
events = 'addRows updateCell update updateRows updateComplete appendCache filterReset filterAndSortReset filterEnd search '
.split( ' ' ).join( c.namespace + 'filter ' );
$table
.removeClass( 'hasFilters' )
@ -410,7 +410,7 @@
}
txt = 'addRows updateCell update updateRows updateComplete appendCache filterReset ' +
'filterResetSaved filterEnd search '.split( ' ' ).join( c.namespace + 'filter ' );
'filterAndSortReset filterResetSaved filterEnd search '.split( ' ' ).join( c.namespace + 'filter ' );
c.$table.bind( txt, function( event, filter ) {
val = wo.filter_hideEmpty &&
$.isEmptyObject( c.cache ) &&
@ -421,9 +421,16 @@
event.stopPropagation();
tsf.buildDefault( table, true );
}
if ( event.type === 'filterReset' ) {
// Add filterAndSortReset - see #1361
if ( event.type === 'filterReset' || event.type === 'filterAndSortReset' ) {
c.$table.find( '.' + tscss.filter ).add( wo.filter_$externalFilters ).val( '' );
tsf.searching( table, [] );
if ( event.type === 'filterAndSortReset' ) {
ts.sortReset( this.config, function() {
tsf.searching( table, [] );
});
} else {
tsf.searching( table, [] );
}
} else if ( event.type === 'filterResetSaved' ) {
ts.storage( table, 'tablesorter-filters', '' );
} else if ( event.type === 'filterEnd' ) {