Filter: compare last search array. Fixes #1363

This commit is contained in:
Rob Garrison 2017-03-28 13:45:59 -05:00
parent 82889c6a92
commit ea73eddab8
2 changed files with 20 additions and 15 deletions

File diff suppressed because one or more lines are too long

View File

@ -883,7 +883,7 @@
wo = c.widgetOptions,
filterArray = $.isArray( filter ),
filters = ( filterArray ) ? filter : ts.getFilters( table, true ),
combinedFilters = ( filters || [] ).join( '' ); // combined filter values
currentFilters = filters || []; // current filter values
// prevent errors if delay init is set
if ( $.isEmptyObject( c.cache ) ) {
// update cache if delayInit set & pager has initialized ( after user initiates a search )
@ -897,7 +897,10 @@
// add filter array back into inputs
if ( filterArray ) {
ts.setFilters( table, filters, false, skipFirst !== true );
if ( !wo.filter_initialized ) { c.lastCombinedFilter = ''; }
if ( !wo.filter_initialized ) {
c.lastSearch = [];
c.lastCombinedFilter = '';
}
}
if ( wo.filter_hideFilters ) {
// show/hide filter row as needed
@ -907,11 +910,11 @@
}
// return if the last search is the same; but filter === false when updating the search
// see example-widget-filter.html filter toggle buttons
if ( c.lastCombinedFilter === combinedFilters && filter !== false ) {
if ( c.lastSearch.join(',') === currentFilters.join(',') && filter !== false ) {
return;
} else if ( filter === false ) {
// force filter refresh
c.lastCombinedFilter = null;
c.lastCombinedFilter = '';
c.lastSearch = [];
}
// define filter inside it is false
@ -928,11 +931,11 @@
if ( c.showProcessing ) {
// give it time for the processing icon to kick in
setTimeout( function() {
tsf.findRows( table, filters, combinedFilters );
tsf.findRows( table, filters, currentFilters );
return false;
}, 30 );
} else {
tsf.findRows( table, filters, combinedFilters );
tsf.findRows( table, filters, currentFilters );
return false;
}
},
@ -1254,9 +1257,11 @@
}
return showRow;
},
findRows: function( table, filters, combinedFilters ) {
if ( table.config.lastCombinedFilter === combinedFilters ||
!table.config.widgetOptions.filter_initialized ) {
findRows: function( table, filters, currentFilters ) {
if (
table.config.lastSearch.join(',') === ( currentFilters || [] ).join(',') ||
!table.config.widgetOptions.filter_initialized
) {
return;
}
var len, norm_rows, rowData, $rows, $row, rowIndex, tbodyIndex, $tbody, columnIndex,
@ -1310,8 +1315,7 @@
// filtered rows count
c.filteredRows = 0;
c.totalRows = 0;
// combindedFilters are undefined on init
combinedFilters = ( storedFilters || [] ).join( '' );
currentFilters = ( storedFilters || [] );
for ( tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++ ) {
$tbody = ts.processTbody( table, c.$tbodies.eq( tbodyIndex ), true );
@ -1324,7 +1328,7 @@
return el[ columnIndex ].$row.get();
}) );
if ( combinedFilters === '' || wo.filter_serversideFiltering ) {
if ( currentFilters.join('') === '' || wo.filter_serversideFiltering ) {
$rows
.removeClass( wo.filter_filteredRow )
.not( '.' + c.cssChildRow )
@ -1499,7 +1503,8 @@
c.totalRows += $rows.length;
ts.processTbody( table, $tbody, false );
}
c.lastCombinedFilter = combinedFilters; // save last search
// lastCombinedFilter is no longer used internally
c.lastCombinedFilter = storedFilters.join(''); // save last search
// don't save 'filters' directly since it may have altered ( AnyMatch column searches )
c.lastSearch = storedFilters;
c.$table.data( 'lastSearch', storedFilters );
@ -1799,7 +1804,7 @@
if ( ( getRaw !== true && wo && !wo.filter_columnFilters ) ||
// setFilters called, but last search is exactly the same as the current
// fixes issue #733 & #903 where calling update causes the input values to reset
( $.isArray(setFilters) && setFilters.join('') === c.lastCombinedFilter ) ) {
( $.isArray(setFilters) && setFilters.join(',') === c.lastSearch.join(',') ) ) {
return $( table ).data( 'lastSearch' );
}
if ( c ) {