diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js index e6685163..f96c7d02 100644 --- a/js/jquery.tablesorter.widgets.js +++ b/js/jquery.tablesorter.widgets.js @@ -245,7 +245,7 @@ ts.addWidget({ ts.benchmark("Applying " + theme + " theme", time); } }, - remove: function(table, c) { + remove: function(table, c, wo) { var $table = c.$table, theme = c.theme || 'jui', themes = ts.themes[ theme ] || ts.themes.jui, @@ -354,7 +354,6 @@ ts.addWidget({ filter_childRows : false, // if true, filter includes child row content in the search filter_columnFilters : true, // if true, a filter will be added to the top of each table column filter_cssFilter : '', // css class name added to the filter row & each input in the row (tablesorter-filter is ALWAYS added) - filter_defaultType : [], // add a default column filter type "~{query}" to make fuzzy searches default; "{q1} AND {q2}" to make all searches use a logical AND. filter_external : '', // jQuery selector string (or jQuery object) of external filters filter_filteredRow : 'filtered', // class added to filtered rows; needed by pager plugin filter_formatter : null, // add custom filter elements to the filter row @@ -411,25 +410,24 @@ ts.filter = { type : /undefined|number/, // check type exact : /(^[\"|\'|=]+)|([\"|\'|=]+$)/g, // exact match (allow '==') nondigit : /[^\w,. \-()]/g, // replace non-digits (from digit & currency parser) - operators : /[<>=]/g, // replace operators - query : /\{query\}/i // replace filter queries + operators : /[<>=]/g // replace operators }, - // function( c, data ) { } - // c = table.config - // data.filter = array of filter input values; data.iFilter = same array, except lowercase - // data.exact = table cell text (or parsed data if column parser enabled) - // data.iExact = same as data.exact, except lowercase - // data.cached = table cell text from cache, so it has been parsed - // data.index = column index; table = table element (DOM) - // data.parsed = array (by column) of boolean values (from filter_useParsedData or "filter-parsed" class) + // function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) + // filter = array of filter input values; iFilter = same array, except lowercase + // exact = table cell text (or parsed data if column parser enabled) + // iExact = same as exact, except lowercase + // cached = table cell text from cache, so it has been parsed + // index = column index; table = table element (DOM) + // wo = widget options (table.config.widgetOptions) + // parsed = array (by column) of boolean values (from filter_useParsedData or "filter-parsed" class) types: { // Look for regex - regex: function( c, data ) { - if ( ts.filter.regex.regex.test(data.iFilter) ) { + regex: function( filter, iFilter, exact, iExact ) { + if ( ts.filter.regex.regex.test(iFilter) ) { var matches, - regex = ts.filter.regex.regex.exec(data.iFilter); + regex = ts.filter.regex.regex.exec(iFilter); try { - matches = new RegExp(regex[1], regex[2]).test( data.iExact ); + matches = new RegExp(regex[1], regex[2]).test( iExact ); } catch (error) { matches = false; } @@ -438,29 +436,27 @@ ts.filter = { return null; }, // Look for operators >, >=, < or <= - operators: function( c, data ) { - if ( /^[<>]=?/.test(data.iFilter) ) { + operators: function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) { + if ( /^[<>]=?/.test(iFilter) ) { var cachedValue, result, - table = c.table, - index = data.index, - parsed = data.parsed[index], - query = ts.formatFloat( data.iFilter.replace(ts.filter.regex.operators, ''), table ), + c = table.config, + query = ts.formatFloat( iFilter.replace(ts.filter.regex.operators, ''), table ), parser = c.parsers[index], savedSearch = query; // parse filter value in case we're comparing numbers (dates) - if (parsed || parser.type === 'numeric') { - result = ts.filter.parseFilter(c, $.trim('' + data.iFilter.replace(ts.filter.regex.operators, '')), index, parsed, true); + if (parsed[index] || parser.type === 'numeric') { + result = ts.filter.parseFilter(table, $.trim('' + iFilter.replace(ts.filter.regex.operators, '')), index, parsed[index], true); query = ( typeof result === "number" && result !== '' && !isNaN(result) ) ? result : query; } // iExact may be numeric - see issue #149; // check if cached is defined, because sometimes j goes out of range? (numeric columns) - cachedValue = ( parsed || parser.type === 'numeric' ) && !isNaN(query) && typeof data.cached !== 'undefined' ? data.cached : - isNaN(data.iExact) ? ts.formatFloat( data.iExact.replace(ts.filter.regex.nondigit, ''), table) : - ts.formatFloat( data.iExact, table ); + cachedValue = ( parsed[index] || parser.type === 'numeric' ) && !isNaN(query) && typeof cached !== 'undefined' ? cached : + isNaN(iExact) ? ts.formatFloat( iExact.replace(ts.filter.regex.nondigit, ''), table) : + ts.formatFloat( iExact, table ); - if ( />/.test(data.iFilter) ) { result = />=/.test(data.iFilter) ? cachedValue >= query : cachedValue > query; } - if ( //.test(iFilter) ) { result = />=/.test(iFilter) ? cachedValue >= query : cachedValue > query; } + if ( /= 0); + var indx = iExact.search( $.trim(iFilter) ); + return iFilter === '' ? true : !(wo.filter_startsWith ? indx === 0 : indx >= 0); } } return null; }, // Look for quotes or equals to get an exact match; ignore type since iExact could be numeric - exact: function( c, data ) { + exact: function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed, rowArray ) { /*jshint eqeqeq:false */ - if (ts.filter.regex.exact.test(data.iFilter)) { - var filter = ts.filter.parseFilter(c, data.iFilter.replace(ts.filter.regex.exact, ''), data.index, data.parsed[data.index]); - return data.anyMatch ? $.inArray(filter, data.rowArray) >= 0 : filter == data.iExact; + if (ts.filter.regex.exact.test(iFilter)) { + var fltr = ts.filter.parseFilter(table, iFilter.replace(ts.filter.regex.exact, ''), index, parsed[index]); + return rowArray ? $.inArray(fltr, rowArray) >= 0 : fltr == iExact; } return null; }, // Look for an AND or && operator (logical and) - and : function( c, data ) { - if ( ts.filter.regex.andTest.test(data.filter) ) { - var index = data.index, - parsed = data.parsed[index], - query = data.iFilter.split( ts.filter.regex.andSplit ), - result = data.iExact.search( $.trim( ts.filter.parseFilter(c, query[0], index, parsed) ) ) >= 0, + and : function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) { + if ( ts.filter.regex.andTest.test(filter) ) { + var query = iFilter.split( ts.filter.regex.andSplit ), + result = iExact.search( $.trim(ts.filter.parseFilter(table, query[0], index, parsed[index])) ) >= 0, indx = query.length - 1; while (result && indx) { - result = result && data.iExact.search( $.trim( ts.filter.parseFilter(c, query[indx], index, parsed) ) ) >= 0; + result = result && iExact.search( $.trim(ts.filter.parseFilter(table, query[indx], index, parsed[index])) ) >= 0; indx--; } return result; @@ -509,55 +502,52 @@ ts.filter = { return null; }, // Look for a range (using " to " or " - ") - see issue #166; thanks matzhu! - range : function( c, data ) { - if ( ts.filter.regex.toTest.test(data.iFilter) ) { + range : function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) { + if ( ts.filter.regex.toTest.test(iFilter) ) { var result, tmp, - table = c.table, - index = data.index, - parsed = data.parsed[index], + c = table.config, // make sure the dash is for a range and not indicating a negative number - query = data.iFilter.split( ts.filter.regex.toSplit ), - range1 = ts.formatFloat( ts.filter.parseFilter(c, query[0].replace(ts.filter.regex.nondigit, ''), index, parsed), table ), - range2 = ts.formatFloat( ts.filter.parseFilter(c, query[1].replace(ts.filter.regex.nondigit, ''), index, parsed), table ); + query = iFilter.split( ts.filter.regex.toSplit ), + range1 = ts.formatFloat( ts.filter.parseFilter(table, query[0].replace(ts.filter.regex.nondigit, ''), index, parsed[index]), table ), + range2 = ts.formatFloat( ts.filter.parseFilter(table, query[1].replace(ts.filter.regex.nondigit, ''), index, parsed[index]), table ); // parse filter value in case we're comparing numbers (dates) - if (parsed || c.parsers[index].type === 'numeric') { + if (parsed[index] || c.parsers[index].type === 'numeric') { result = c.parsers[index].format('' + query[0], table, c.$headers.eq(index), index); range1 = (result !== '' && !isNaN(result)) ? result : range1; result = c.parsers[index].format('' + query[1], table, c.$headers.eq(index), index); range2 = (result !== '' && !isNaN(result)) ? result : range2; } - result = ( parsed || c.parsers[index].type === 'numeric' ) && !isNaN(range1) && !isNaN(range2) ? data.cached : - isNaN(data.iExact) ? ts.formatFloat( data.iExact.replace(ts.filter.regex.nondigit, ''), table) : - ts.formatFloat( data.iExact, table ); + result = ( parsed[index] || c.parsers[index].type === 'numeric' ) && !isNaN(range1) && !isNaN(range2) ? cached : + isNaN(iExact) ? ts.formatFloat( iExact.replace(ts.filter.regex.nondigit, ''), table) : + ts.formatFloat( iExact, table ); if (range1 > range2) { tmp = range1; range1 = range2; range2 = tmp; } // swap return (result >= range1 && result <= range2) || (range1 === '' || range2 === ''); } return null; }, // Look for wild card: ? = single, * = multiple, or | = logical OR - wild : function( c, data ) { - if ( /[\?|\*]/.test(data.iFilter) || ts.filter.regex.orReplace.test(data.filter) ) { - var index = data.index, - parsed = data.parsed[index], - query = ts.filter.parseFilter(c, data.iFilter.replace(ts.filter.regex.orReplace, "|"), index, parsed); + wild : function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed, rowArray ) { + if ( /[\?|\*]/.test(iFilter) || ts.filter.regex.orReplace.test(filter) ) { + var c = table.config, + query = ts.filter.parseFilter(table, iFilter.replace(ts.filter.regex.orReplace, "|"), index, parsed[index]); // look for an exact match with the "or" unless the "filter-match" class is found if (!c.$headers.filter('[data-column="' + index + '"]:last').hasClass('filter-match') && /\|/.test(query)) { - query = data.anyMatch && $.isArray(data.rowArray) ? '(' + query + ')' : '^(' + query + ')$'; + query = $.isArray(rowArray) ? '(' + query + ')' : '^(' + query + ')$'; } // parsing the filter may not work properly when using wildcards =/ - return new RegExp( query.replace(/\?/g, '\\S{1}').replace(/\*/g, '\\S*') ).test(data.iExact); + return new RegExp( query.replace(/\?/g, '\\S{1}').replace(/\*/g, '\\S*') ).test(iExact); } return null; }, // fuzzy text search; modified from https://github.com/mattyork/fuzzy (MIT license) - fuzzy: function( c, data ) { - if ( /^~/.test(data.iFilter) ) { + fuzzy: function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) { + if ( /^~/.test(iFilter) ) { var indx, patternIndx = 0, - len = data.iExact.length, - pattern = ts.filter.parseFilter(c, data.iFilter.slice(1), data.index, data.parsed[data.index]); + len = iExact.length, + pattern = ts.filter.parseFilter(table, iFilter.slice(1), index, parsed[index]); for (indx = 0; indx < len; indx++) { - if (data.iExact[indx] === pattern[patternIndx]) { + if (iExact[indx] === pattern[patternIndx]) { patternIndx += 1; } } @@ -790,9 +780,10 @@ ts.filter = { c.$table.data('lastSearch', filters); return filters; }, - parseFilter: function(c, filter, column, parsed, forceParse){ + parseFilter: function(table, filter, column, parsed, forceParse){ + var c = table.config; return forceParse || parsed ? - c.parsers[column].format( filter, c.table, [], column ) : + c.parsers[column].format( filter, table, [], column ) : filter; }, buildRow: function(table, c, wo) { @@ -1002,26 +993,24 @@ ts.filter = { }, findRows: function(table, filters, combinedFilters) { if (table.config.lastCombinedFilter === combinedFilters) { return; } - var len, $rows, rowIndex, tbodyIndex, $tbody, $cells, columnIndex, - childRow, lastSearch, matches, result, showRow, time, val, indx, - query, notFiltered, searchFiltered, filterMatched, fxn, ffxn, + var cached, len, $rows, rowIndex, tbodyIndex, $tbody, $cells, columnIndex, + childRow, childRowText, exact, iExact, iFilter, lastSearch, matches, result, + notFiltered, searchFiltered, filterMatched, showRow, time, val, indx, + anyMatch, iAnyMatch, rowArray, rowText, iRowText, rowCache, fxn, ffxn, regex = ts.filter.regex, c = table.config, wo = c.widgetOptions, + columns = c.columns, $tbodies = c.$table.children('tbody'), // target all tbodies #568 - // data object passed to filters; anyMatch is a flag for the filters - data = { anyMatch: false }, // anyMatch really screws up with these types of filters - noAnyMatch = [ 'range', 'notMatch', 'operators' ]; - - // parse columns after formatter, in case the class is added at that point - data.parsed = c.$headers.map(function(columnIndex) { - return c.parsers && c.parsers[columnIndex] && c.parsers[columnIndex].parsed || - // getData won't return "parsed" if other "filter-" class names exist (e.g.