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,31 +45,53 @@ jQuery(function($){
this.ts = $.tablesorter;
// filter widget table
this.$table = $('#testblock').html('<table class="tablesorter">' +
'<thead><tr>' +
'<th class="rank">Rank</th>' +
'<th class="first filter-match">First Name</th>' +
'<th class="last">Last Name</th>' +
'<th data-value="<20">Age</th>' +
'<th class="total">Total</th>' +
'<th>Discount</th>' +
'<th>Date</th>' +
'<th class="last2">Last Name2</th>' +
'</tr></thead><tbody>' +
'<tr><td>1</td><td>Philip Aaron Wong</td><td>Johnson Sr Esq</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2004 7:22 AM</td><td>Johnson Sr Esq</td></tr>' +
'<tr><td>11</td><td>Aaron</td><td>Hibert</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2009 12:21 PM</td><td>Hibert</td></tr>' +
'<tr><td>12</td><td>Brandon Clark</td><td>Henry Jr</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2000 1:15 PM</td><td>Henry Jr</td></tr>' +
'<tr><td>111</td><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td><td>Parker</td></tr>' +
'<tr><td>21</td><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td><td>Hood</td></tr>' +
'<tr><td>013</td><td>Clark</td><td>Kent Sr.</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td><td>Kent Sr.</td></tr>' +
'<tr><td>005</td><td>Bruce</td><td>Almighty Esq</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2021 9:12 AM</td><td>Almighty Esq</td></tr>' +
'<tr><td>10</td><td>Alex</td><td>Dumass</td><td>13</td><td>$5.29</td><td>4%</td><td>Jan 8, 2012 5:11 PM</td><td>Dumass</td></tr>' +
'<tr><td>16</td><td>Jim</td><td>Franco</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2004 11:23 AM</td><td>Franco</td></tr>' +
'<tr><td>166</td><td>Bruce Lee</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td><td>Evans</td></tr>' +
'<tr><td>100</td><td>Brenda Dexter</td><td>McMasters</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2010 7:23 PM</td><td>McMasters</td></tr>' +
'<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');
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>' +
'<th class="first filter-match">First Name</th>' +
'<th class="last">Last Name</th>' +
'<th data-value="<20">Age</th>' +
'<th class="total">Total</th>' +
'<th>Discount</th>' +
'<th>Date</th>' +
'<th class="last2">Last Name2</th>' +
'</tr></thead><tbody>' +
'<tr><td>1</td><td>Philip Aaron Wong</td><td>Johnson Sr Esq</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2004 7:22 AM</td><td>Johnson Sr Esq</td></tr>' +
'<tr><td>11</td><td>Aaron</td><td>Hibert</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2009 12:21 PM</td><td>Hibert</td></tr>' +
'<tr><td>12</td><td>Brandon Clark</td><td>Henry Jr</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2000 1:15 PM</td><td>Henry Jr</td></tr>' +
'<tr><td>111</td><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td><td>Parker</td></tr>' +
'<tr><td>21</td><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td><td>Hood</td></tr>' +
'<tr><td>013</td><td>Clark</td><td>Kent Sr.</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td><td>Kent Sr.</td></tr>' +
'<tr><td>005</td><td>Bruce</td><td>Almighty Esq</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2021 9:12 AM</td><td>Almighty Esq</td></tr>' +
'<tr><td>10</td><td>Alex</td><td>Dumass</td><td>13</td><td>$5.29</td><td>4%</td><td>Jan 8, 2012 5:11 PM</td><td>Dumass</td></tr>' +
'<tr><td>16</td><td>Jim</td><td>Franco</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2004 11:23 AM</td><td>Franco</td></tr>' +
'<tr><td>166</td><td>Bruce Lee</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td><td>Evans</td></tr>' +
'<tr><td>100</td><td>Brenda Dexter</td><td>McMasters</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2010 7:23 PM</td><td>McMasters</td></tr>' +
'<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