Filter: select defaults to exact match again. Fixes #1136

This commit is contained in:
Rob Garrison 2016-01-22 13:36:09 -06:00
parent bb7b57d0a1
commit 7f08f7dd1d
3 changed files with 76 additions and 30 deletions

View File

@ -1209,7 +1209,8 @@
c.$headerIndexed[ columnIndex ].hasClass( 'filter-parsed' ) );
vars.functions[ columnIndex ] =
ts.getColumnData( table, wo.filter_functions, columnIndex );
ts.getColumnData( table, wo.filter_functions, columnIndex ) ||
c.$headerIndexed[ columnIndex ].hasClass( 'filter-select' );
vars.defaultColFilter[ columnIndex ] =
ts.getColumnData( table, wo.filter_defaultFilter, columnIndex ) || '';
vars.excludeFilter[ columnIndex ] =

View File

@ -45,6 +45,26 @@ jQuery(function($){
this.ts = $.tablesorter;
// filter widget table
if ( /\(table2\)/.test(assert.test.testName) ) {
this.$table = $('#testblock').html('<table class="tablesorter">' +
'<thead><tr>' +
'<th class="filter-select">AlphaNumeric</th>' +
'<th class="filter-select filter-match">Numeric</th>' +
'<th>Animals</th>' +
'<th>Sites</th>' +
'</tr></thead><tbody>' +
'<tr><td>abc</td><td>1</td><td>Koala</td><td>http://www.google.com</td></tr>' +
'<tr><td>abc 1</td><td>234</td><td>Ox</td><td>http://www.yahoo.com</td></tr>' +
'<tr><td>abc 9</td><td>111</td><td>Girafee</td><td>http://www.facebook.com</td></tr>' +
'<tr><td>zyx 24</td><td>123</td><td>Bison</td><td>http://www.whitehouse.gov/</td></tr>' +
'<tr><td>abc 11</td><td>3</td><td>Chimp</td><td>http://www.ucla.edu/</td></tr>' +
'<tr><td>abc 2</td><td>56</td><td>Elephant</td><td>http://www.wikipedia.org/</td></tr>' +
'<tr><td>abc 9</td><td>155</td><td>Lion</td><td>http://www.nytimes.com/</td></tr>' +
'<tr><td>ABC 10</td><td>87</td><td>Zebra</td><td>http://www.google.com</td></tr>' +
'<tr><td>zyx 1</td><td>999</td><td>Koala</td><td>http://www.mit.edu/</td></tr>' +
'<tr><td>zyx 12</td><td>0</td><td>Llama</td><td>http://www.nasa.gov/</td></tr>' +
'</tbody></table>').find('table');
} else {
this.$table = $('#testblock').html('<table class="tablesorter">' +
'<thead><tr>' +
'<th class="rank">Rank</th>' +
@ -70,6 +90,8 @@ jQuery(function($){
'<tr><td>55</td><td>Dennis</td><td>Bronson</td><td>65</td><td>$123.00</td><td></td><td>Jan 20, 2001 1:12 PM</td><td>Bronson</td></tr>' +
'<tr><td>9</td><td>Martha</td><td>delFuego</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2011 10:55 AM</td><td>delFuego</td></tr>' +
'</tbody></table>').find('table');
}
this.table = this.$table[0];
this.init = false;
@ -85,8 +107,8 @@ jQuery(function($){
filter_functions : {
'.last2' : true,
'.rank' : {
"< 10" : function(e, n) { return n <= 10; },
"> 10" : function(e, n) { return n > 10; }
'< 10' : function(e, n) { return n <= 10; },
'> 10' : function(e, n) { return n > 10; }
}
},
filter_selectSource : {
@ -322,8 +344,31 @@ jQuery(function($){
opts.push( $.trim( $(this).text() ) );
});
assert.equal ( 'len=' + opts.length + ',' + opts.join(''), 'len=4,abcdefzyx', 'filter_selectSource set' );
});
QUnit.test( 'Filter: select & matching (table2)', function(assert) {
var self = this,
ts = this.ts,
$table = this.$table,
table = this.table;
expect(3);
return QUnit.SequentialRunner(
function(actions, assertions) {
return QUnit.assertOnEvent($table, 'filterEnd', actions, assertions);
}
).nextTask(
function(){ ts.setFilters( table, ['abc 1'], true ); },
function(){ assert.cacheCompare( table, 0, ['abc 1'], 'select exact search', true ); }
).nextTask(
function(){
$table.find( '.filter-select' ).eq(0).addClass( 'filter-match' );
ts.setFilters( table, [ 'abc 1' ], true ); },
function(){ assert.cacheCompare( table, 0, ['abc 1', 'abc 11', 'ABC 10'], 'select match search', true ); }
).nextTask(
function(){ ts.setFilters( table, ['', '1'], true ); },
function(){ assert.cacheCompare( table, 1, [ 1, 111, 123, 155], 'select match seach', true ); }
).promise();
});
});

View File

@ -45,7 +45,7 @@ QUnit.SequentialRunner = function(runnerCreator){
next: function(runner) {
this.defer = this.defer.then( QUnit.deferredCallback(runner) );
return this;
},
}
};
if (runnerCreator) {
result.nextTask = function(args) { // any argument list