Filter: allow dynamically changing "anyMatch" filter. Fixes #998

previously, once an anyMatch type filter was found, it's value was always used to do an anyMatch search. Now the script checks to see if the input is targeting more than one column
This commit is contained in:
Mottie 2015-08-21 12:57:54 -05:00
parent 3a207c99ef
commit 47de48ef5d
9 changed files with 98 additions and 42 deletions

View File

@ -1,4 +1,4 @@
/*! tablesorter (FORK) - updated 08-19-2015 (v2.23.1)*/
/*! tablesorter (FORK) - updated 08-21-2015 (v2.23.1)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -3413,7 +3413,8 @@
ts.filter.searching( table, true, true );
})
.bind( 'search change keypress '.split( ' ' ).join( namespace + ' ' ), function( event ) {
var column = $( this ).data( 'column' );
// don't get cached data, in case data-column changes dynamically
var column = parseInt( $( this ).attr( 'data-column' ), 10 );
// don't allow 'change' event to process if the input value is the same - fixes #685
if ( event.which === 13 || event.type === 'search' ||
event.type === 'change' && this.value !== c.lastSearch[column] ) {
@ -3564,6 +3565,9 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( ts.filter.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
return parseInt( val, 10 );
}
// process column range
if ( targets && /-/.test( val ) ) {
ranges = val.match( /(\d+)\s*-\s*(\d+)/g );
@ -3621,16 +3625,23 @@
return filterMatched;
},
processRow: function( c, data, vars ) {
var columnIndex, hasSelect, result, val, filterMatched,
var hasSelect, result, val, filterMatched,
fxn, ffxn, txt,
regex = ts.filter.regex,
wo = c.widgetOptions,
showRow = true;
showRow = true,
// if wo.filter_$anyMatch data-column attribute is changed dynamically
// we don't want to do an "anyMatch" search on one column using data
// for the entire row - see #998
columnIndex = wo.filter_$anyMatch && wo.filter_$anyMatch.length ?
// look for multiple columns '1-3,4-6,8'
ts.filter.multipleColumns( c, wo.filter_$anyMatch ) :
[];
data.$cells = data.$row.children();
if ( data.anyMatchFlag ) {
// look for multiple columns '1-3,4-6,8'
columnIndex = ts.filter.multipleColumns( c, wo.filter_$anyMatch );
if ( data.anyMatchFlag && columnIndex.length > 1 ) {
data.anyMatch = true;
data.isMatch = true;
data.rowArray = data.$cells.map( function( i ) {

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*! tablesorter (FORK) - updated 08-19-2015 (v2.23.1)*/
/*! tablesorter (FORK) - updated 08-21-2015 (v2.23.1)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -1107,7 +1107,8 @@
ts.filter.searching( table, true, true );
})
.bind( 'search change keypress '.split( ' ' ).join( namespace + ' ' ), function( event ) {
var column = $( this ).data( 'column' );
// don't get cached data, in case data-column changes dynamically
var column = parseInt( $( this ).attr( 'data-column' ), 10 );
// don't allow 'change' event to process if the input value is the same - fixes #685
if ( event.which === 13 || event.type === 'search' ||
event.type === 'change' && this.value !== c.lastSearch[column] ) {
@ -1258,6 +1259,9 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( ts.filter.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
return parseInt( val, 10 );
}
// process column range
if ( targets && /-/.test( val ) ) {
ranges = val.match( /(\d+)\s*-\s*(\d+)/g );
@ -1315,16 +1319,23 @@
return filterMatched;
},
processRow: function( c, data, vars ) {
var columnIndex, hasSelect, result, val, filterMatched,
var hasSelect, result, val, filterMatched,
fxn, ffxn, txt,
regex = ts.filter.regex,
wo = c.widgetOptions,
showRow = true;
showRow = true,
// if wo.filter_$anyMatch data-column attribute is changed dynamically
// we don't want to do an "anyMatch" search on one column using data
// for the entire row - see #998
columnIndex = wo.filter_$anyMatch && wo.filter_$anyMatch.length ?
// look for multiple columns '1-3,4-6,8'
ts.filter.multipleColumns( c, wo.filter_$anyMatch ) :
[];
data.$cells = data.$row.children();
if ( data.anyMatchFlag ) {
// look for multiple columns '1-3,4-6,8'
columnIndex = ts.filter.multipleColumns( c, wo.filter_$anyMatch );
if ( data.anyMatchFlag && columnIndex.length > 1 ) {
data.anyMatch = true;
data.isMatch = true;
data.rowArray = data.$cells.map( function( i ) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -481,7 +481,7 @@
<li><a href="example-widget-column-selector.html">Column selector widget</a> (<span class="version">v2.15</span>; <span class="version updated">v2.23.0</span>).</li>
<li><a href="example-widget-editable.html">Content editable widget</a> (v2.9; <span class="version updated">v2.23.0</span>).</li>
<li><span class="label label-info">Beta</span> <a href="example-dragtable.html">Dragtable mod</a> - (jQuery UI widget for column reordering [<a href="http://stackoverflow.com/a/27770224/145346">ref</a>]; <span class="version">v2.19.0</span>).</li>
<li><span class="results">&dagger;</span> Filter widget (<span class="version updated">v2.23.0</span>):
<li><span class="results">&dagger;</span> Filter widget (<span class="version updated">v2.23.2</span>):
<ul>
<li><a href="example-widget-filter.html">basic</a> (v2.0.18; <span class="version updated">v2.22.2</span>)</li>
<li><a href="example-widget-filter-any-match.html">external option (match any column)</a> (<span class="version">v2.13.3</span>; <span class="version updated">v2.22.0</span>)</li>
@ -7012,6 +7012,7 @@ $.tablesorter.isDigit( &quot;(2,345.67)&quot; );</pre>
<li><code>$els</code> - jQuery object of all input (search) elements to bind.</li>
<li><code>false</code> - boolean flag to force a new search.</li>
</ul>
<p>The <code>table</code> element will only process one table. So if you pass in a jQuery object, only the <em>first table</em> will be bound to the elements (<code>$els</code>).</p>
The external elements (<code>$els</code>) will allow searching the table using "search" and "keyup" events (enter to start &amp; escape to cancel the search), and uses the <a href="#widget-filter-livesearch"><code>filter_liveSearch</code></a> option, or delayed search.<br>
<br>
Include a <code>data-column="#"</code> attribute (where <code>#</code> is the column number) in the search input, to specify to which column the search should apply ~ see <a href="example-widget-filter-external-inputs.html">this demo</a> for a full example. <span class="label label-warning">Warning!</span>, if no <code>data-column</code> attribute is added to the input, the input will be ignored.<br>

View File

@ -4,7 +4,7 @@
*/
/*! tablesorter (FORK) - updated 08-19-2015 (v2.23.1)*/
/*! tablesorter (FORK) - updated 08-21-2015 (v2.23.1)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -3419,7 +3419,8 @@
ts.filter.searching( table, true, true );
})
.bind( 'search change keypress '.split( ' ' ).join( namespace + ' ' ), function( event ) {
var column = $( this ).data( 'column' );
// don't get cached data, in case data-column changes dynamically
var column = parseInt( $( this ).attr( 'data-column' ), 10 );
// don't allow 'change' event to process if the input value is the same - fixes #685
if ( event.which === 13 || event.type === 'search' ||
event.type === 'change' && this.value !== c.lastSearch[column] ) {
@ -3570,6 +3571,9 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( ts.filter.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
return parseInt( val, 10 );
}
// process column range
if ( targets && /-/.test( val ) ) {
ranges = val.match( /(\d+)\s*-\s*(\d+)/g );
@ -3627,16 +3631,23 @@
return filterMatched;
},
processRow: function( c, data, vars ) {
var columnIndex, hasSelect, result, val, filterMatched,
var hasSelect, result, val, filterMatched,
fxn, ffxn, txt,
regex = ts.filter.regex,
wo = c.widgetOptions,
showRow = true;
showRow = true,
// if wo.filter_$anyMatch data-column attribute is changed dynamically
// we don't want to do an "anyMatch" search on one column using data
// for the entire row - see #998
columnIndex = wo.filter_$anyMatch && wo.filter_$anyMatch.length ?
// look for multiple columns '1-3,4-6,8'
ts.filter.multipleColumns( c, wo.filter_$anyMatch ) :
[];
data.$cells = data.$row.children();
if ( data.anyMatchFlag ) {
// look for multiple columns '1-3,4-6,8'
columnIndex = ts.filter.multipleColumns( c, wo.filter_$anyMatch );
if ( data.anyMatchFlag && columnIndex.length > 1 ) {
data.anyMatch = true;
data.isMatch = true;
data.rowArray = data.$cells.map( function( i ) {

View File

@ -4,7 +4,7 @@
*/
/*! tablesorter (FORK) - updated 08-19-2015 (v2.23.1)*/
/*! tablesorter (FORK) - updated 08-21-2015 (v2.23.1)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -1113,7 +1113,8 @@
ts.filter.searching( table, true, true );
})
.bind( 'search change keypress '.split( ' ' ).join( namespace + ' ' ), function( event ) {
var column = $( this ).data( 'column' );
// don't get cached data, in case data-column changes dynamically
var column = parseInt( $( this ).attr( 'data-column' ), 10 );
// don't allow 'change' event to process if the input value is the same - fixes #685
if ( event.which === 13 || event.type === 'search' ||
event.type === 'change' && this.value !== c.lastSearch[column] ) {
@ -1264,6 +1265,9 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( ts.filter.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
return parseInt( val, 10 );
}
// process column range
if ( targets && /-/.test( val ) ) {
ranges = val.match( /(\d+)\s*-\s*(\d+)/g );
@ -1321,16 +1325,23 @@
return filterMatched;
},
processRow: function( c, data, vars ) {
var columnIndex, hasSelect, result, val, filterMatched,
var hasSelect, result, val, filterMatched,
fxn, ffxn, txt,
regex = ts.filter.regex,
wo = c.widgetOptions,
showRow = true;
showRow = true,
// if wo.filter_$anyMatch data-column attribute is changed dynamically
// we don't want to do an "anyMatch" search on one column using data
// for the entire row - see #998
columnIndex = wo.filter_$anyMatch && wo.filter_$anyMatch.length ?
// look for multiple columns '1-3,4-6,8'
ts.filter.multipleColumns( c, wo.filter_$anyMatch ) :
[];
data.$cells = data.$row.children();
if ( data.anyMatchFlag ) {
// look for multiple columns '1-3,4-6,8'
columnIndex = ts.filter.multipleColumns( c, wo.filter_$anyMatch );
if ( data.anyMatchFlag && columnIndex.length > 1 ) {
data.anyMatch = true;
data.isMatch = true;
data.rowArray = data.$cells.map( function( i ) {

View File

@ -739,7 +739,8 @@
ts.filter.searching( table, true, true );
})
.bind( 'search change keypress '.split( ' ' ).join( namespace + ' ' ), function( event ) {
var column = $( this ).data( 'column' );
// don't get cached data, in case data-column changes dynamically
var column = parseInt( $( this ).attr( 'data-column' ), 10 );
// don't allow 'change' event to process if the input value is the same - fixes #685
if ( event.which === 13 || event.type === 'search' ||
event.type === 'change' && this.value !== c.lastSearch[column] ) {
@ -890,6 +891,9 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( ts.filter.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
return parseInt( val, 10 );
}
// process column range
if ( targets && /-/.test( val ) ) {
ranges = val.match( /(\d+)\s*-\s*(\d+)/g );
@ -947,16 +951,23 @@
return filterMatched;
},
processRow: function( c, data, vars ) {
var columnIndex, hasSelect, result, val, filterMatched,
var hasSelect, result, val, filterMatched,
fxn, ffxn, txt,
regex = ts.filter.regex,
wo = c.widgetOptions,
showRow = true;
showRow = true,
// if wo.filter_$anyMatch data-column attribute is changed dynamically
// we don't want to do an "anyMatch" search on one column using data
// for the entire row - see #998
columnIndex = wo.filter_$anyMatch && wo.filter_$anyMatch.length ?
// look for multiple columns '1-3,4-6,8'
ts.filter.multipleColumns( c, wo.filter_$anyMatch ) :
[];
data.$cells = data.$row.children();
if ( data.anyMatchFlag ) {
// look for multiple columns '1-3,4-6,8'
columnIndex = ts.filter.multipleColumns( c, wo.filter_$anyMatch );
if ( data.anyMatchFlag && columnIndex.length > 1 ) {
data.anyMatch = true;
data.isMatch = true;
data.rowArray = data.$cells.map( function( i ) {