mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-10-08 13:44:18 +00:00
Core: Refer headers option by header class/id
This commit is contained in:
parent
05f9dbf4e7
commit
4627f214b8
@ -219,7 +219,7 @@
|
|||||||
var c = table.config,
|
var c = table.config,
|
||||||
// update table bodies in case we start with an empty table
|
// update table bodies in case we start with an empty table
|
||||||
tb = c.$tbodies = c.$table.children('tbody:not(.' + c.cssInfoBlock + ')'),
|
tb = c.$tbodies = c.$table.children('tbody:not(.' + c.cssInfoBlock + ')'),
|
||||||
rows, list, l, i, h, ch, p, time, indx,
|
rows, list, l, i, h, ch, p, time,
|
||||||
j = 0,
|
j = 0,
|
||||||
parsersDebug = "",
|
parsersDebug = "",
|
||||||
len = tb.length;
|
len = tb.length;
|
||||||
@ -233,16 +233,11 @@
|
|||||||
while (j < len) {
|
while (j < len) {
|
||||||
rows = tb[j].rows;
|
rows = tb[j].rows;
|
||||||
if (rows[j]) {
|
if (rows[j]) {
|
||||||
l = rows[j].cells.length;
|
l = c.columns; // rows[j].cells.length;
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
// tons of thanks to AnthonyM1229 for working out the following selector (issue #74) to make this work in IE8!
|
h = c.$headers.filter('[data-column="' + i + '"]:last');
|
||||||
// More fixes to this selector to work properly in iOS and jQuery 1.8+ (issue #132 & #174)
|
// get column indexed table cell
|
||||||
h = c.$headers.filter(':not([colspan])');
|
ch = ts.getColumnData( table, c.headers, i );
|
||||||
h = h.add( c.$headers.filter('[colspan="1"]') ) // ie8 fix
|
|
||||||
.filter('[data-column="' + i + '"]:last');
|
|
||||||
// get headers option corrected index
|
|
||||||
indx = c.$headers.index(h);
|
|
||||||
ch = c.headers[indx];
|
|
||||||
// get column parser
|
// get column parser
|
||||||
p = ts.getParserById( ts.getData(h, ch, 'sorter') );
|
p = ts.getParserById( ts.getData(h, ch, 'sorter') );
|
||||||
// empty cells behaviour - keeping emptyToBottom for backwards compatibility
|
// empty cells behaviour - keeping emptyToBottom for backwards compatibility
|
||||||
@ -421,10 +416,12 @@
|
|||||||
c.columns = ts.computeColumnIndex( c.$table.children('thead, tfoot').children('tr') );
|
c.columns = ts.computeColumnIndex( c.$table.children('thead, tfoot').children('tr') );
|
||||||
// add icon if cssIcon option exists
|
// add icon if cssIcon option exists
|
||||||
i = c.cssIcon ? '<i class="' + ( c.cssIcon === ts.css.icon ? ts.css.icon : c.cssIcon + ' ' + ts.css.icon ) + '"></i>' : '';
|
i = c.cssIcon ? '<i class="' + ( c.cssIcon === ts.css.icon ? ts.css.icon : c.cssIcon + ' ' + ts.css.icon ) + '"></i>' : '';
|
||||||
c.$headers = $(table).find(c.selectorHeaders).each(function(index) {
|
c.$headers.each(function(index) {
|
||||||
$t = $(this);
|
$t = $(this);
|
||||||
ch = c.headers[index];
|
// make sure to get header cell & not column indexed cell
|
||||||
c.headerContent[index] = $(this).html(); // save original header content
|
ch = ts.getColumnData( table, c.headers, index, true );
|
||||||
|
// save original header content
|
||||||
|
c.headerContent[index] = $(this).html();
|
||||||
// set up header template
|
// set up header template
|
||||||
t = c.headerTemplate.replace(/\{content\}/g, $(this).html()).replace(/\{icon\}/g, i);
|
t = c.headerTemplate.replace(/\{content\}/g, $(this).html()).replace(/\{icon\}/g, i);
|
||||||
if (c.onRenderTemplate) {
|
if (c.onRenderTemplate) {
|
||||||
@ -473,10 +470,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateHeader(table) {
|
function updateHeader(table) {
|
||||||
var s, $th, c = table.config;
|
var s, $th,
|
||||||
|
c = table.config;
|
||||||
c.$headers.each(function(index, th){
|
c.$headers.each(function(index, th){
|
||||||
$th = $(th);
|
$th = $(th);
|
||||||
s = ts.getData( th, c.headers[index], 'sorter' ) === 'false';
|
s = ts.getData( th, ts.getColumnData( table, c.headers, index, true ), 'sorter' ) === 'false';
|
||||||
th.sortDisabled = s;
|
th.sortDisabled = s;
|
||||||
$th[ s ? 'addClass' : 'removeClass' ]('sorter-false').attr('aria-disabled', '' + s);
|
$th[ s ? 'addClass' : 'removeClass' ]('sorter-false').attr('aria-disabled', '' + s);
|
||||||
// aria-controls - requires table ID
|
// aria-controls - requires table ID
|
||||||
@ -1012,6 +1010,7 @@
|
|||||||
c.$table = $table
|
c.$table = $table
|
||||||
.addClass(ts.css.table + ' ' + c.tableClass + k)
|
.addClass(ts.css.table + ' ' + c.tableClass + k)
|
||||||
.attr({ role : 'grid'});
|
.attr({ role : 'grid'});
|
||||||
|
c.$headers = $(table).find(c.selectorHeaders);
|
||||||
|
|
||||||
// give the table a unique id, which will be used in namespace binding
|
// give the table a unique id, which will be used in namespace binding
|
||||||
if (!c.namespace) {
|
if (!c.namespace) {
|
||||||
@ -1089,6 +1088,31 @@
|
|||||||
if (typeof c.initialized === 'function') { c.initialized(table); }
|
if (typeof c.initialized === 'function') { c.initialized(table); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ts.getColumnData = function(table, obj, indx, getCell){
|
||||||
|
if (typeof obj === 'undefined' || obj === null) { return; }
|
||||||
|
table = $(table)[0];
|
||||||
|
var result, $h, k,
|
||||||
|
c = table.config;
|
||||||
|
if (obj[indx]) {
|
||||||
|
return getCell ? obj[indx] : obj[c.$headers.index( c.$headers.filter('[data-column="' + indx + '"]:last') )];
|
||||||
|
}
|
||||||
|
for (k in obj) {
|
||||||
|
if (typeof k === 'string') {
|
||||||
|
if (getCell) {
|
||||||
|
// get header cell
|
||||||
|
$h = c.$headers.eq(indx).filter(k);
|
||||||
|
} else {
|
||||||
|
// get column indexed cell
|
||||||
|
$h = c.$headers.filter('[data-column="' + indx + '"]:last').filter(k);
|
||||||
|
}
|
||||||
|
if ($h.length) {
|
||||||
|
return obj[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
// computeTableHeaderCellIndexes from:
|
// computeTableHeaderCellIndexes from:
|
||||||
// http://www.javascripttoolbox.com/lib/table/examples.php
|
// http://www.javascripttoolbox.com/lib/table/examples.php
|
||||||
// http://www.javascripttoolbox.com/temp/table_cellindex.html
|
// http://www.javascripttoolbox.com/temp/table_cellindex.html
|
||||||
@ -1442,6 +1466,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ts.getParserById = function(name) {
|
ts.getParserById = function(name) {
|
||||||
|
/*jshint eqeqeq:false */
|
||||||
|
if (name == 'false') { return false; }
|
||||||
var i, l = ts.parsers.length;
|
var i, l = ts.parsers.length;
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
if (ts.parsers[i].id.toLowerCase() === (name.toString()).toLowerCase()) {
|
if (ts.parsers[i].id.toLowerCase() === (name.toString()).toLowerCase()) {
|
||||||
@ -1717,7 +1743,7 @@
|
|||||||
if (s) {
|
if (s) {
|
||||||
var c = table.config,
|
var c = table.config,
|
||||||
ci = c.$headers.filter('[data-column=' + cellIndex + ']:last'),
|
ci = c.$headers.filter('[data-column=' + cellIndex + ']:last'),
|
||||||
format = ci.length && ci[0].dateFormat || ts.getData( ci, c.headers[cellIndex], 'dateFormat') || c.dateFormat;
|
format = ci.length && ci[0].dateFormat || ts.getData( ci, ts.getColumnData( table, c.headers, cellIndex ), 'dateFormat') || c.dateFormat;
|
||||||
s = s.replace(/\s+/g," ").replace(/[\-.,]/g, "/"); // escaped - because JSHint in Firefox was showing it as an error
|
s = s.replace(/\s+/g," ").replace(/[\-.,]/g, "/"); // escaped - because JSHint in Firefox was showing it as an error
|
||||||
if (format === "mmddyyyy") {
|
if (format === "mmddyyyy") {
|
||||||
s = s.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/, "$3/$1/$2");
|
s = s.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/, "$3/$1/$2");
|
||||||
|
@ -718,10 +718,9 @@ ts.filter = {
|
|||||||
$header = c.$headers.filter('[data-column="' + column + '"]:last');
|
$header = c.$headers.filter('[data-column="' + column + '"]:last');
|
||||||
buildSelect = (wo.filter_functions && wo.filter_functions[column] && typeof wo.filter_functions[column] !== 'function') ||
|
buildSelect = (wo.filter_functions && wo.filter_functions[column] && typeof wo.filter_functions[column] !== 'function') ||
|
||||||
$header.hasClass('filter-select');
|
$header.hasClass('filter-select');
|
||||||
// get data from jQuery data, metadata, headers option or header class name
|
|
||||||
if (ts.getData) {
|
if (ts.getData) {
|
||||||
// get data from jQuery data, metadata, headers option or header class name
|
// get data from jQuery data, metadata, headers option or header class name
|
||||||
disabled = ts.getData($header[0], c.headers[column], 'filter') === 'false';
|
disabled = ts.getData($header[0], ts.getColumnData( table, column ), 'filter') === 'false';
|
||||||
} else {
|
} else {
|
||||||
// only class names and header options - keep this for compatibility with tablesorter v2.0.5
|
// only class names and header options - keep this for compatibility with tablesorter v2.0.5
|
||||||
disabled = (c.headers[column] && c.headers[column].hasOwnProperty('filter') && c.headers[column].filter === false) ||
|
disabled = (c.headers[column] && c.headers[column].hasOwnProperty('filter') && c.headers[column].filter === false) ||
|
||||||
@ -898,7 +897,7 @@ ts.filter = {
|
|||||||
parsed = c.$headers.map(function(columnIndex) {
|
parsed = c.$headers.map(function(columnIndex) {
|
||||||
return c.parsers && c.parsers[columnIndex] && c.parsers[columnIndex].parsed ||
|
return c.parsers && c.parsers[columnIndex] && c.parsers[columnIndex].parsed ||
|
||||||
// getData won't return "parsed" if other "filter-" class names exist (e.g. <th class="filter-select filter-parsed">)
|
// getData won't return "parsed" if other "filter-" class names exist (e.g. <th class="filter-select filter-parsed">)
|
||||||
ts.getData && ts.getData(c.$headers.filter('[data-column="' + columnIndex + '"]:last'), c.headers[columnIndex], 'filter') === 'parsed' ||
|
ts.getData && ts.getData(c.$headers.filter('[data-column="' + columnIndex + '"]:last'), ts.getColumnData( table, c.headers, columnIndex ), 'filter') === 'parsed' ||
|
||||||
$(this).hasClass('filter-parsed');
|
$(this).hasClass('filter-parsed');
|
||||||
}).get();
|
}).get();
|
||||||
if (c.debug) { time = new Date(); }
|
if (c.debug) { time = new Date(); }
|
||||||
@ -1511,7 +1510,7 @@ ts.addWidget({
|
|||||||
var canResize,
|
var canResize,
|
||||||
$column = $(this);
|
$column = $(this);
|
||||||
column = $column.attr('data-column');
|
column = $column.attr('data-column');
|
||||||
canResize = ts.getData( $column, c.headers[column], 'resizable') === "false";
|
canResize = ts.getData( $column, ts.getColumnData( table, c.headers, column ), 'resizable') === "false";
|
||||||
$rows.children().filter('[data-column="' + column + '"]')[canResize ? 'addClass' : 'removeClass']('resizable-false');
|
$rows.children().filter('[data-column="' + column + '"]')[canResize ? 'addClass' : 'removeClass']('resizable-false');
|
||||||
});
|
});
|
||||||
// add wrapper inside each cell to allow for positioning of the resizable target block
|
// add wrapper inside each cell to allow for positioning of the resizable target block
|
||||||
|
@ -109,7 +109,7 @@ ts.addWidget({
|
|||||||
.wrap('<div class="tablesorter-scroller-header" style="width:' + $tbl.width() + ';" />')
|
.wrap('<div class="tablesorter-scroller-header" style="width:' + $tbl.width() + ';" />')
|
||||||
.find('.' + ts.css.header);
|
.find('.' + ts.css.header);
|
||||||
|
|
||||||
$tbl.wrap('<div class="tablesorter-scroller-table" style="height:' + h + 'px;width:' + $tbl.width() + ';overflow-y:scroll;" />')
|
$tbl.wrap('<div class="tablesorter-scroller-table" style="height:' + h + 'px;width:' + $tbl.width() + ';overflow-y:scroll;" />');
|
||||||
|
|
||||||
// make scroller header sortable
|
// make scroller header sortable
|
||||||
ts.bindEvents(table, $cells);
|
ts.bindEvents(table, $cells);
|
||||||
|
@ -126,6 +126,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div id="testblock" class="tester"></div>
|
<div id="testblock" class="tester"></div>
|
||||||
|
<div id="testblock2" class="tester"></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -2,7 +2,8 @@
|
|||||||
* TableSorter QUnit Testing
|
* TableSorter QUnit Testing
|
||||||
*/
|
*/
|
||||||
/*jshint unused: false */
|
/*jshint unused: false */
|
||||||
/*global QUnit: false, JSHINT: false, ok: false, start: false, deepEqual: false, asyncTest: false */
|
/*global start: false, asyncTest: false, equal: false, $: false, expect: false, module: false,
|
||||||
|
tester: false, test: false, stop: false */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Filter widget tested parts
|
Filter widget tested parts
|
||||||
@ -76,7 +77,6 @@ $(function(){
|
|||||||
Filter widget
|
Filter widget
|
||||||
************************************************/
|
************************************************/
|
||||||
init = false,
|
init = false,
|
||||||
runOnce = false,
|
|
||||||
|
|
||||||
runFilterTests = function(){
|
runFilterTests = function(){
|
||||||
|
|
||||||
@ -100,210 +100,210 @@ $(function(){
|
|||||||
expect(27);
|
expect(27);
|
||||||
|
|
||||||
callbackName = 'regular';
|
callbackName = 'regular';
|
||||||
callback['regular'] = function(){
|
callback.regular = function(){
|
||||||
tester.cacheCompare( table, 1, ['Peter', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter', 'Dennis'], 'search regular', true );
|
tester.cacheCompare( table, 1, ['Peter', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter', 'Dennis'], 'search regular', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', 'e'], true );
|
ts.setFilters( table, ['', 'e'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'fuzzy1';
|
callbackName = 'fuzzy1';
|
||||||
callback['fuzzy1'] = function(){
|
callback.fuzzy1 = function(){
|
||||||
tester.cacheCompare( table, 1, ['Bruce Lee', 'Brenda Dexter'], 'search fuzzy', true );
|
tester.cacheCompare( table, 1, ['Bruce Lee', 'Brenda Dexter'], 'search fuzzy', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '~bee'], true );
|
ts.setFilters( table, ['', '~bee'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'fuzzy2';
|
callbackName = 'fuzzy2';
|
||||||
callback['fuzzy2'] = function(){
|
callback.fuzzy2 = function(){
|
||||||
tester.cacheCompare( table, 1, ['Philip Aaron Wong'], 'search fuzzy2', true );
|
tester.cacheCompare( table, 1, ['Philip Aaron Wong'], 'search fuzzy2', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '~piano'], true );
|
ts.setFilters( table, ['', '~piano'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'exact';
|
callbackName = 'exact';
|
||||||
callback['exact'] = function(){
|
callback.exact = function(){
|
||||||
tester.cacheCompare( table, 1, ['John'], 'search exact', true );
|
tester.cacheCompare( table, 1, ['John'], 'search exact', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', 'john='], true );
|
ts.setFilters( table, ['', 'john='], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'wildcard1';
|
callbackName = 'wildcard1';
|
||||||
callback['wildcard1'] = function(){
|
callback.wildcard1 = function(){
|
||||||
tester.cacheCompare( table, 2, ['Dumass', 'Evans'], 'search wildcard, one character (?)', true );
|
tester.cacheCompare( table, 2, ['Dumass', 'Evans'], 'search wildcard, one character (?)', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', 'a?s'], true );
|
ts.setFilters( table, ['', '', 'a?s'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'wildcard2';
|
callbackName = 'wildcard2';
|
||||||
callback['wildcard2'] = function(){
|
callback.wildcard2 = function(){
|
||||||
tester.cacheCompare( table, 2, ['Dumass', 'Evans', 'McMasters'], 'search wildcard, multiple characters (*)', true );
|
tester.cacheCompare( table, 2, ['Dumass', 'Evans', 'McMasters'], 'search wildcard, multiple characters (*)', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', 'a*s'], true );
|
ts.setFilters( table, ['', '', 'a*s'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'regex';
|
callbackName = 'regex';
|
||||||
callback['regex'] = function(){
|
callback.regex = function(){
|
||||||
tester.cacheCompare( table, 1, ['Peter', 'Brenda Dexter'], 'search regex', true );
|
tester.cacheCompare( table, 1, ['Peter', 'Brenda Dexter'], 'search regex', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '/r$/'], true );
|
ts.setFilters( table, ['', '/r$/'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator';
|
callbackName = 'operator';
|
||||||
callback['operator'] = function(){
|
callback.operator = function(){
|
||||||
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 );
|
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 );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '>10'], true );
|
ts.setFilters( table, ['', '', '', '', '>10'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator1';
|
callbackName = 'operator1';
|
||||||
callback['operator1'] = function(){
|
callback.operator1 = function(){
|
||||||
tester.cacheCompare( table, 4, [153.19, 123], 'search operator (>100); ensure search filtered gets cleared', true );
|
tester.cacheCompare( table, 4, [153.19, 123], 'search operator (>100); ensure search filtered gets cleared', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '>100'], true );
|
ts.setFilters( table, ['', '', '', '', '>100'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator2';
|
callbackName = 'operator2';
|
||||||
callback['operator2'] = function(){
|
callback.operator2 = function(){
|
||||||
tester.cacheCompare( table, 5, [22, 20, 25, 44, 44, 32], 'search operator (>=)', true );
|
tester.cacheCompare( table, 5, [22, 20, 25, 44, 44, 32], 'search operator (>=)', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '', '>=20'], true );
|
ts.setFilters( table, ['', '', '', '', '', '>=20'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator3';
|
callbackName = 'operator3';
|
||||||
callback['operator3'] = function(){
|
callback.operator3 = function(){
|
||||||
tester.cacheCompare( table, 5, [5, 4], 'search operator (<10)', true );
|
tester.cacheCompare( table, 5, [5, 4], 'search operator (<10)', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '', '<10'], true );
|
ts.setFilters( table, ['', '', '', '', '', '<10'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator4';
|
callbackName = 'operator4';
|
||||||
callback['operator4'] = function(){
|
callback.operator4 = function(){
|
||||||
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 );
|
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 );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '', '<100'], true );
|
ts.setFilters( table, ['', '', '', '', '', '<100'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator5';
|
callbackName = 'operator5';
|
||||||
callback['operator5'] = function(){
|
callback.operator5 = function(){
|
||||||
tester.cacheCompare( table, 5, [5, 18, 20, 4, 14, 11, 15, 17], 'search operator (<=)', true );
|
tester.cacheCompare( table, 5, [5, 18, 20, 4, 14, 11, 15, 17], 'search operator (<=)', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '', '<=20'], true );
|
ts.setFilters( table, ['', '', '', '', '', '<=20'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator6';
|
callbackName = 'notMatch';
|
||||||
callback['operator6'] = function(){
|
callback.notMatch = function(){
|
||||||
tester.cacheCompare( table, 1, ['Peter', 'John', 'Bruce', 'Jim', 'Bruce Lee', 'Dennis'], 'search not match', true );
|
tester.cacheCompare( table, 1, ['Peter', 'John', 'Bruce', 'Jim', 'Bruce Lee', 'Dennis'], 'search not match', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '!a'], true );
|
ts.setFilters( table, ['', '!a'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator7';
|
callbackName = 'notMatch2';
|
||||||
callback['operator7'] = function(){
|
callback.notMatch2 = function(){
|
||||||
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 );
|
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 );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '!aa'], true );
|
ts.setFilters( table, ['', '!aa'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator8';
|
callbackName = 'operatorAnd';
|
||||||
callback['operator8'] = function(){
|
callback.operatorAnd = function(){
|
||||||
tester.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Bruce Lee'], 'search and match', true );
|
tester.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Bruce Lee'], 'search and match', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', 'br && c'], true );
|
ts.setFilters( table, ['', 'br && c'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator9';
|
callbackName = 'operatorAnd2';
|
||||||
callback['operator9'] = function(){
|
callback.operatorAnd2 = function(){
|
||||||
tester.cacheCompare( table, 1, ['Brandon Clark'], 'search and match; ensure search filtered gets cleared', true );
|
tester.cacheCompare( table, 1, ['Brandon Clark'], 'search and match; ensure search filtered gets cleared', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', 'br && cl'], true );
|
ts.setFilters( table, ['', 'br && cl'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator10';
|
callbackName = 'operatorOr';
|
||||||
callback['operator10'] = function(){
|
callback.operatorOr = function(){
|
||||||
tester.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search OR match', true );
|
tester.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search OR match', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', 'alex|br*'], true );
|
ts.setFilters( table, ['', 'alex|br*'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator11';
|
callbackName = 'range';
|
||||||
callback['operator11'] = function(){
|
callback.range = function(){
|
||||||
tester.cacheCompare( table, 4, [5.95, 9.99, 5.29], 'search range', true );
|
tester.cacheCompare( table, 4, [5.95, 9.99, 5.29], 'search range', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '5 - 10'], true );
|
ts.setFilters( table, ['', '', '', '', '5 - 10'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
callbackName = 'operator12';
|
callbackName = 'range2';
|
||||||
callback['operator12'] = function(){
|
callback.range2 = function(){
|
||||||
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 );
|
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 );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '5 - 100'], true );
|
ts.setFilters( table, ['', '', '', '', '5 - 100'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
// test filter_startsWith (false by default)
|
// test filter_startsWith (false by default)
|
||||||
wo.filter_startsWith = false;
|
wo.filter_startsWith = false;
|
||||||
callbackName = 'startsWith';
|
callbackName = 'startsWith';
|
||||||
callback['startsWith'] = function(){
|
callback.startsWith = function(){
|
||||||
tester.cacheCompare( table, 1, ['Philip Aaron Wong', 'Aaron'], 'search - filter_startsWith : false', true );
|
tester.cacheCompare( table, 1, ['Philip Aaron Wong', 'Aaron'], 'search - filter_startsWith : false', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', 'aa'], true );
|
ts.setFilters( table, ['', 'aa'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
// test filter_startsWith (false by default)
|
// test filter_startsWith (false by default)
|
||||||
wo.filter_startsWith = true;
|
wo.filter_startsWith = true;
|
||||||
callbackName = 'startsWith2';
|
callbackName = 'startsWith2';
|
||||||
callback['startsWith2'] = function(){
|
callback.startsWith2 = function(){
|
||||||
tester.cacheCompare( table, 1, ['Aaron'], 'search - filter_startsWith : true', true );
|
tester.cacheCompare( table, 1, ['Aaron'], 'search - filter_startsWith : true', true );
|
||||||
wo.filter_startsWith = false;
|
wo.filter_startsWith = false;
|
||||||
}
|
};
|
||||||
c.$table.trigger('search', false);
|
c.$table.trigger('search', false);
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
// test filter_ignoreCase (true by default)
|
// test filter_ignoreCase (true by default)
|
||||||
wo.filter_ignoreCase = false;
|
wo.filter_ignoreCase = false;
|
||||||
callbackName = 'ignoreCase';
|
callbackName = 'ignoreCase1';
|
||||||
callback['ignoreCase'] = function(){
|
callback.ignoreCase1 = function(){
|
||||||
tester.cacheCompare( table, 1, [], 'search - filter_ignoreCase : false', true );
|
tester.cacheCompare( table, 1, [], 'search - filter_ignoreCase : false', true );
|
||||||
wo.filter_ignoreCase = true;
|
wo.filter_ignoreCase = true;
|
||||||
}
|
};
|
||||||
c.$table.trigger('search', false);
|
c.$table.trigger('search', false);
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
// test filter-match class (added in the example code)
|
// test filter-match class (added in the example code)
|
||||||
callbackName = 'filterMatch';
|
callbackName = 'filterMatch';
|
||||||
callback['filterMatch'] = function(){
|
callback.filterMatch = function(){
|
||||||
tester.cacheCompare( table, 1, ['Brandon Clark', 'Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search - filter-match', true );
|
tester.cacheCompare( table, 1, ['Brandon Clark', 'Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search - filter-match', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', 'alex|br*|c'], true );
|
ts.setFilters( table, ['', 'alex|br*|c'], true );
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
// test filter-match class
|
// test filter-match class
|
||||||
c.$table.find('.tablesorter-header').eq(1).removeClass('filter-match');
|
c.$table.find('.tablesorter-header').eq(1).removeClass('filter-match');
|
||||||
callbackName = 'notFilterMatch';
|
callbackName = 'notFilterMatch';
|
||||||
callback['notFilterMatch'] = function(){
|
callback.notFilterMatch = function(){
|
||||||
tester.cacheCompare( table, 1, ['Bruce', 'Alex'], 'search - filter-match removed', true );
|
tester.cacheCompare( table, 1, ['Bruce', 'Alex'], 'search - filter-match removed', true );
|
||||||
}
|
};
|
||||||
c.$table.trigger('search', false);
|
c.$table.trigger('search', false);
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
// filter reset
|
// filter reset
|
||||||
callbackName = 'filterReset';
|
callbackName = 'filterReset';
|
||||||
callback['filterReset'] = function(){
|
callback.filterReset = function(){
|
||||||
tester.cacheCompare( table, 5, [22, 5, 18, 20, 25, 44, 44, 4, 14, 11, 15, 32, 17], 'filterReset', true );
|
tester.cacheCompare( table, 5, [22, 5, 18, 20, 25, 44, 44, 4, 14, 11, 15, 32, 17], 'filterReset', true );
|
||||||
}
|
};
|
||||||
c.$table.trigger('filterReset');
|
c.$table.trigger('filterReset');
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
// filter parsed class
|
// filter parsed class
|
||||||
wo.filter_startsWith = false;
|
wo.filter_startsWith = false;
|
||||||
callbackName = 'filterParsed';
|
callbackName = 'filterParsed';
|
||||||
callback['filterParsed'] = function(){
|
callback.filterParsed = function(){
|
||||||
tester.cacheCompare( table, 6, [ new Date('Oct 13, 2000 1:15 PM').getTime() ], 'search - filter-parsed', true );
|
tester.cacheCompare( table, 6, [ new Date('Oct 13, 2000 1:15 PM').getTime() ], 'search - filter-parsed', true );
|
||||||
}
|
};
|
||||||
ts.setFilters( table, ['', '', '', '', '', '', '< 1/1/2001'], true );
|
ts.setFilters( table, ['', '', '', '', '', '', '< 1/1/2001'], true );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$table.on('filterEnd', function(e){
|
$table.on('filterEnd', function(){
|
||||||
start();
|
start();
|
||||||
if (callbackName !== '' && callback[callbackName]) {
|
if (callbackName !== '' && callback[callbackName]) {
|
||||||
callback[callbackName]();
|
callback[callbackName]();
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
* TableSorter QUnit Testing
|
* TableSorter QUnit Testing
|
||||||
*/
|
*/
|
||||||
/*jshint unused: false */
|
/*jshint unused: false */
|
||||||
/*global QUnit: false, JSHINT: false, ok: false, start: false, deepEqual: false, asyncTest: false */
|
/*global QUnit: false, JSHINT: false, ok: false, start: false, deepEqual: false, asyncTest: false,
|
||||||
|
strictEqual: false, jQuery: false, equal: false, $: false, expect: false, module: false,
|
||||||
|
test: false, stop: false, ipv6tests: false */
|
||||||
|
|
||||||
/************************************************
|
/************************************************
|
||||||
QUnit skip testing
|
QUnit skip testing
|
||||||
@ -133,6 +135,7 @@ $(function(){
|
|||||||
table2 = $table2[0],
|
table2 = $table2[0],
|
||||||
table3 = $table3[0],
|
table3 = $table3[0],
|
||||||
table4 = $table4[0],
|
table4 = $table4[0],
|
||||||
|
table5 = $table5[0],
|
||||||
th0 = $table1.find('th')[0], // first table header cell
|
th0 = $table1.find('th')[0], // first table header cell
|
||||||
init = false,
|
init = false,
|
||||||
sortIndx = 0,
|
sortIndx = 0,
|
||||||
@ -142,7 +145,7 @@ $(function(){
|
|||||||
returnTime = function(string){
|
returnTime = function(string){
|
||||||
return new Date(string).getTime();
|
return new Date(string).getTime();
|
||||||
},
|
},
|
||||||
undef, c1, c2, c3, c4, e, i, l, t;
|
undef, c1, c2, c3, c4, e, i, t;
|
||||||
|
|
||||||
$table1
|
$table1
|
||||||
.bind('tablesorter-initialized', function(){
|
.bind('tablesorter-initialized', function(){
|
||||||
@ -224,7 +227,6 @@ $(function(){
|
|||||||
var internalColumn = true,
|
var internalColumn = true,
|
||||||
dataColumn = true;
|
dataColumn = true;
|
||||||
$table4.find('thead th').each(function(i){
|
$table4.find('thead th').each(function(i){
|
||||||
var $this = $(this);
|
|
||||||
internalColumn = internalColumn && this.column === i;
|
internalColumn = internalColumn && this.column === i;
|
||||||
dataColumn = dataColumn && $(this).attr('data-column') == i;
|
dataColumn = dataColumn && $(this).attr('data-column') == i;
|
||||||
});
|
});
|
||||||
@ -320,6 +322,75 @@ $(function(){
|
|||||||
strictEqual( ts.replaceAccents('\u00e7\u0107\u010d\u00c7\u0106\u010c\u00df\u1e9e'), 'cccCCCssSS', "replaced c & s sharp");
|
strictEqual( ts.replaceAccents('\u00e7\u0107\u010d\u00c7\u0106\u010c\u00df\u1e9e'), 'cccCCCssSS', "replaced c & s sharp");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
detect parsers
|
||||||
|
************************************************/
|
||||||
|
asyncTest( "detect parsers", function() {
|
||||||
|
expect(2);
|
||||||
|
$('#testblock2').html('<table class="tablesorter"><thead>' +
|
||||||
|
'<tr><th class="col-off" colspan="2">Info</th><th class="col-off" colspan="4">Details</th></tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<th class="col-first">First Name</th>' +
|
||||||
|
'<th class="col-last">Last Name</th>' +
|
||||||
|
'<th class="col-age" id="age">Age</th>' +
|
||||||
|
'<th class="col-total">Total</th>' +
|
||||||
|
'<th class="col-discount">Discount</th>' +
|
||||||
|
'<th class="col-date">Date</th>' +
|
||||||
|
'</tr></thead>' +
|
||||||
|
'<tbody>' +
|
||||||
|
'<tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>' +
|
||||||
|
'<tr><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>' +
|
||||||
|
'<tr><td>Clark</td><td>Kent</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>' +
|
||||||
|
'<tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>' +
|
||||||
|
'<tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>' +
|
||||||
|
'</tbody></table>')
|
||||||
|
.find('table')
|
||||||
|
.tablesorter({
|
||||||
|
headers : {
|
||||||
|
0 : { sorter: false },
|
||||||
|
1 : { sorter: false },
|
||||||
|
3 : { sorter: 'digit' } // 3 sets the 4th column, not the 3rd header cell now
|
||||||
|
},
|
||||||
|
initialized: function(table){
|
||||||
|
start();
|
||||||
|
var i,
|
||||||
|
result = true,
|
||||||
|
parsers = [ 'text', 'digit', 'digit', 'currency', 'percent', 'usLongDate' ],
|
||||||
|
c = table.config;
|
||||||
|
for (i = 0; i < c.columns; i++){
|
||||||
|
result = result && c.parsers[i].id === parsers[i];
|
||||||
|
}
|
||||||
|
equal( result, true, 'detect parsers by header index' );
|
||||||
|
stop();
|
||||||
|
// table inception!
|
||||||
|
$(table)
|
||||||
|
.trigger('destroy')
|
||||||
|
.tablesorter({
|
||||||
|
headers : {
|
||||||
|
'.col-first' : { sorter: 'url' },
|
||||||
|
'.col-off' : { sorter: false },
|
||||||
|
'.col-total' : { sorter : 'percent' },
|
||||||
|
'#age, .col-last' : { sorter: 'currency' },
|
||||||
|
'.col-date' : { sorter : 'time' },
|
||||||
|
'.col-discount' : { sorter: 'digit' }
|
||||||
|
},
|
||||||
|
initialized: function(table){
|
||||||
|
var i,
|
||||||
|
result = true,
|
||||||
|
parsers = [ 'url', 'currency', 'currency', 'percent', 'digit', 'time' ],
|
||||||
|
c = table.config;
|
||||||
|
for (i = 0; i < c.columns; i++){
|
||||||
|
result = result && c.parsers[i].id === parsers[i];
|
||||||
|
}
|
||||||
|
equal( result, true, 'detect parsers by class/id' );
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
/************************************************
|
/************************************************
|
||||||
check all default parsers
|
check all default parsers
|
||||||
************************************************/
|
************************************************/
|
||||||
@ -353,6 +424,7 @@ $(function(){
|
|||||||
for (i = 0; i < p.length; i++) {
|
for (i = 0; i < p.length; i++) {
|
||||||
t = p[i].id;
|
t = p[i].id;
|
||||||
if (s.hasOwnProperty(t)) {
|
if (s.hasOwnProperty(t)) {
|
||||||
|
/*jshint loopfunc:true */
|
||||||
$.each(s[t], function(k,v){
|
$.each(s[t], function(k,v){
|
||||||
// check "is" and "format" functions
|
// check "is" and "format" functions
|
||||||
if (p[i].is(k)) {
|
if (p[i].is(k)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user