2014-04-23 21:11:13 +00:00
|
|
|
/*!
|
|
|
|
* TableSorter QUnit Testing
|
|
|
|
*/
|
|
|
|
/*jshint unused: false */
|
2014-05-08 17:05:01 +00:00
|
|
|
/*global start: false, asyncTest: false, equal: false, $: false, expect: false, module: false,
|
|
|
|
tester: false, test: false, stop: false */
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
/*
|
2014-05-03 04:47:52 +00:00
|
|
|
Filter widget tested parts
|
2014-04-23 21:11:13 +00:00
|
|
|
========================
|
|
|
|
OPTIONS:
|
2014-05-15 00:53:03 +00:00
|
|
|
filter_defaultAttrib, filter_ignoreCase, filter_startsWith,
|
|
|
|
filter_selectSource, filter_functions (set, not functionality)
|
2014-05-03 04:47:52 +00:00
|
|
|
|
|
|
|
CLASSES:
|
|
|
|
filter-false, filter-match, filter-parsed
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
METHODS:
|
2014-05-03 04:47:52 +00:00
|
|
|
filterReset, search (false), setFilters
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
EVENTS:
|
2014-05-03 04:47:52 +00:00
|
|
|
filterInit, filterEnd
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
Not yet tested
|
|
|
|
=========================
|
|
|
|
OPTIONS:
|
2014-05-03 04:47:52 +00:00
|
|
|
filter_childRows, filter_columnFilters, filter_cssFilter, filter_external,
|
2014-05-15 00:53:03 +00:00
|
|
|
filter_filteredRow, filter_formatter, filter_hideEmpty,
|
2014-05-03 04:47:52 +00:00
|
|
|
filter_hideEmpty, filter_liveSearch, filter_onlyAvail, filter_placeholder,
|
2014-05-15 00:53:03 +00:00
|
|
|
filter_reset, filter_saveFilters, filter_searchDelay,
|
2014-05-03 04:47:52 +00:00
|
|
|
filter_serversideFiltering, filter_useParsedData
|
|
|
|
|
|
|
|
CLASSES:
|
|
|
|
filter-select, filter-select-nosort, filter-onlyAvail
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
METHODS:
|
2014-05-03 04:47:52 +00:00
|
|
|
search (array), getFilters, external filters
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
EVENTS:
|
2014-05-03 04:47:52 +00:00
|
|
|
filterStart
|
2014-04-23 21:11:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
$(function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
module('Widgets');
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
var ts = $.tablesorter,
|
2014-05-03 04:47:52 +00:00
|
|
|
callback = {},
|
|
|
|
callbackName = 'init',
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
// filter widget table
|
|
|
|
$table = $('#testblock').html('<table class="tablesorter">' +
|
|
|
|
'<thead><tr>' +
|
2014-05-15 00:53:03 +00:00
|
|
|
'<th class="rank">Rank</th>' +
|
|
|
|
'<th class="first filter-match">First Name</th>' +
|
|
|
|
'<th class="last">Last Name</th>' +
|
2014-04-23 21:11:13 +00:00
|
|
|
'<th data-value="<20">Age</th>' +
|
2014-05-15 00:53:03 +00:00
|
|
|
'<th class="total">Total</th>' +
|
2014-04-23 21:11:13 +00:00
|
|
|
'<th>Discount</th>' +
|
|
|
|
'<th>Date</th>' +
|
2014-05-15 00:53:03 +00:00
|
|
|
'<th class="last2">Last Name2</th>' +
|
2014-04-23 21:11:13 +00:00
|
|
|
'</tr></thead><tbody>' +
|
2014-05-15 00:53:03 +00:00
|
|
|
'<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>32%</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>' +
|
2014-04-23 21:11:13 +00:00
|
|
|
'</tbody></table>').find('table'),
|
|
|
|
table = $table[0],
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
Filter widget
|
|
|
|
************************************************/
|
|
|
|
init = false,
|
|
|
|
|
|
|
|
runFilterTests = function(){
|
|
|
|
|
|
|
|
var c = table.config,
|
|
|
|
wo = c.widgetOptions;
|
|
|
|
|
2014-05-03 04:47:52 +00:00
|
|
|
test( 'Filter: init', function() {
|
|
|
|
expect(6);
|
2014-04-23 21:11:13 +00:00
|
|
|
|
2014-05-03 04:47:52 +00:00
|
|
|
equal( init, true, 'Init event' );
|
|
|
|
equal( $table.hasClass('hasFilters'), true, '`hasFilters` class applied' );
|
2014-04-23 21:11:13 +00:00
|
|
|
|
2014-05-03 04:47:52 +00:00
|
|
|
equal( ts.filter.regex.child.test( c.cssChildRow ), true, 'child row regex check' );
|
|
|
|
equal( ts.filter.regex.filtered.test( wo.filter_filteredRow ), true, 'filtered row regex check' );
|
2014-05-15 00:53:03 +00:00
|
|
|
// this includes check of headers option & referencing column by class
|
|
|
|
equal ( c.$table.find('.tablesorter-filter').eq(0).hasClass('disabled'), true, 'filter disabled & headers class name working' );
|
2014-04-23 21:11:13 +00:00
|
|
|
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 3, [ 12, 18, 13, 18 ], 'starting filter value on age column', true );
|
2014-04-23 21:11:13 +00:00
|
|
|
});
|
|
|
|
|
2014-05-03 04:47:52 +00:00
|
|
|
asyncTest( 'Filter searches', function() {
|
|
|
|
expect(27);
|
|
|
|
|
|
|
|
callbackName = 'regular';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.regular = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Peter', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter', 'Dennis'], 'search regular', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', 'e'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'fuzzy1';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.fuzzy1 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Bruce Lee', 'Brenda Dexter'], 'search fuzzy', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '~bee'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'fuzzy2';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.fuzzy2 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Philip Aaron Wong'], 'search fuzzy2', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '~piano'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'exact';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.exact = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['John'], 'search exact', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', 'john='], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'wildcard1';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.wildcard1 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 2, ['Dumass', 'Evans'], 'search wildcard, one character (?)', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', 'a?s'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'wildcard2';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.wildcard2 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 2, ['Dumass', 'Evans', 'McMasters'], 'search wildcard, multiple characters (*)', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', 'a*s'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'regex';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.regex = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Peter', 'Brenda Dexter'], 'search regex', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '/r$/'], true );
|
|
|
|
stop();
|
2014-04-23 21:11:13 +00:00
|
|
|
|
2014-05-03 04:47:52 +00:00
|
|
|
callbackName = 'operator';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.operator = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 4, [42.29, 19.99, 15.89, 153.19, 14.19, 13.19, 55.2, 123, 22.09], 'search operator (>10)', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '>10'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'operator1';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.operator1 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 4, [153.19, 123], 'search operator (>100); ensure search filtered gets cleared', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '>100'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'operator2';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.operator2 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 5, [22, 20, 25, 44, 44, 32], 'search operator (>=)', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '', '>=20'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'operator3';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.operator3 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 5, [5, 4], 'search operator (<10)', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '', '<10'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'operator4';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.operator4 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 5, [22, 5, 18, 20, 25, 44, 44, 4, 14, 11, 15, 32, 17], 'search operator (<100); ensure search filtered gets cleared', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '', '<100'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
callbackName = 'operator5';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.operator5 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 5, [5, 18, 20, 4, 14, 11, 15, 17], 'search operator (<=)', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '', '<=20'], true );
|
|
|
|
stop();
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'notMatch';
|
|
|
|
callback.notMatch = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Peter', 'John', 'Bruce', 'Jim', 'Bruce Lee', 'Dennis'], 'search not match', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '!a'], true );
|
|
|
|
stop();
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'notMatch2';
|
|
|
|
callback.notMatch2 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Brandon Clark', 'Peter', 'John', 'Clark', 'Bruce', 'Alex', 'Jim', 'Bruce Lee', 'Brenda Dexter', 'Dennis', 'Martha'], 'search not match; ensure search filtered gets cleared', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '!aa'], true );
|
|
|
|
stop();
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'operatorAnd';
|
|
|
|
callback.operatorAnd = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Bruce Lee'], 'search and match', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', 'br && c'], true );
|
|
|
|
stop();
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'operatorAnd2';
|
|
|
|
callback.operatorAnd2 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Brandon Clark'], 'search and match; ensure search filtered gets cleared', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', 'br && cl'], true );
|
|
|
|
stop();
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'operatorOr';
|
|
|
|
callback.operatorOr = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search OR match', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', 'alex|br*'], true );
|
|
|
|
stop();
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'range';
|
|
|
|
callback.range = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 4, [5.95, 9.99, 5.29], 'search range', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '5 - 10'], true );
|
|
|
|
stop();
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'range2';
|
|
|
|
callback.range2 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 4, [5.95, 42.29, 9.99, 19.99, 15.89, 5.29, 14.19, 13.19, 55.2, 22.09], 'search range; ensure search filtered gets cleared', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '5 - 100'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// test filter_startsWith (false by default)
|
|
|
|
wo.filter_startsWith = false;
|
|
|
|
callbackName = 'startsWith';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.startsWith = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Philip Aaron Wong', 'Aaron'], 'search - filter_startsWith : false', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', 'aa'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// test filter_startsWith (false by default)
|
|
|
|
wo.filter_startsWith = true;
|
|
|
|
callbackName = 'startsWith2';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.startsWith2 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Aaron'], 'search - filter_startsWith : true', true );
|
|
|
|
wo.filter_startsWith = false;
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
c.$table.trigger('search', false);
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// test filter_ignoreCase (true by default)
|
|
|
|
wo.filter_ignoreCase = false;
|
2014-05-08 17:05:01 +00:00
|
|
|
callbackName = 'ignoreCase1';
|
|
|
|
callback.ignoreCase1 = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, [], 'search - filter_ignoreCase : false', true );
|
|
|
|
wo.filter_ignoreCase = true;
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
c.$table.trigger('search', false);
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// test filter-match class (added in the example code)
|
|
|
|
callbackName = 'filterMatch';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.filterMatch = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Brandon Clark', 'Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search - filter-match', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', 'alex|br*|c'], true );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// test filter-match class
|
|
|
|
c.$table.find('.tablesorter-header').eq(1).removeClass('filter-match');
|
|
|
|
callbackName = 'notFilterMatch';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.notFilterMatch = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 1, ['Bruce', 'Alex'], 'search - filter-match removed', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
c.$table.trigger('search', false);
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// filter reset
|
|
|
|
callbackName = 'filterReset';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.filterReset = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 5, [22, 5, 18, 20, 25, 44, 44, 4, 14, 11, 15, 32, 17], 'filterReset', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
c.$table.trigger('filterReset');
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// filter parsed class
|
|
|
|
wo.filter_startsWith = false;
|
|
|
|
callbackName = 'filterParsed';
|
2014-05-08 17:05:01 +00:00
|
|
|
callback.filterParsed = function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
tester.cacheCompare( table, 6, [ new Date('Oct 13, 2000 1:15 PM').getTime() ], 'search - filter-parsed', true );
|
2014-05-08 17:05:01 +00:00
|
|
|
};
|
2014-05-03 04:47:52 +00:00
|
|
|
ts.setFilters( table, ['', '', '', '', '', '', '< 1/1/2001'], true );
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-05-15 00:53:03 +00:00
|
|
|
test( 'Filter: function & selectSource', function() {
|
|
|
|
expect(3);
|
|
|
|
|
|
|
|
var $t, opts = [];
|
|
|
|
$t = c.$table.find('.tablesorter-filter-row select:last');
|
|
|
|
equal ( $t.length !== 0, true, 'filter_functions: true working' );
|
|
|
|
|
|
|
|
c.$table.find('.tablesorter-filter-row select:first option').each(function(){
|
|
|
|
opts.push( $.trim( $(this).text() ) );
|
|
|
|
});
|
|
|
|
equal ( opts.length === 3 && opts.join('') === '< 10> 10', true, 'filter_functions set' );
|
|
|
|
|
|
|
|
opts = [];
|
|
|
|
$t.find('option').each(function(){
|
|
|
|
opts.push( $.trim( $(this).text() ) );
|
|
|
|
});
|
|
|
|
equal ( opts.length === 4 && opts.join('') === 'abcdefzyx', true, 'filter_selectSource set' );
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-05-08 17:05:01 +00:00
|
|
|
$table.on('filterEnd', function(){
|
2014-05-03 04:47:52 +00:00
|
|
|
start();
|
|
|
|
if (callbackName !== '' && callback[callbackName]) {
|
|
|
|
callback[callbackName]();
|
|
|
|
}
|
|
|
|
callbackName = '';
|
|
|
|
});
|
2014-04-23 21:11:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$table
|
|
|
|
.on('filterInit', function(){
|
|
|
|
init = true;
|
|
|
|
})
|
2014-05-03 04:47:52 +00:00
|
|
|
.on('filterEnd.init', function(){
|
|
|
|
runFilterTests();
|
|
|
|
$table.off('filterEnd.init');
|
2014-04-23 21:11:13 +00:00
|
|
|
})
|
|
|
|
.tablesorter({
|
2014-05-03 04:47:52 +00:00
|
|
|
ignoreCase: false,
|
2014-05-15 00:53:03 +00:00
|
|
|
widgets: ['zebra', 'filter'],
|
|
|
|
headers: {
|
|
|
|
'.rank' : { filter: false }
|
|
|
|
},
|
|
|
|
widgetOptions: {
|
|
|
|
filter_functions : {
|
|
|
|
'.last2' : true,
|
|
|
|
'.rank' : {
|
|
|
|
"< 10" : function(e, n) { return n <= 10; },
|
|
|
|
"> 10" : function(e, n) { return n > 10; }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filter_selectSource : {
|
|
|
|
// Alphanumeric match (prefix only)
|
|
|
|
// added as select2 options (you could also use select2 data option)
|
|
|
|
'.last2' : function(table, column) {
|
|
|
|
return ['abc', 'def', 'zyx'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-23 21:11:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|