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