Editable: trim everything! & revert widget changes

This commit is contained in:
Mottie 2014-08-27 18:06:22 -05:00
parent 718257447f
commit dbecda238c
2 changed files with 116 additions and 139 deletions

View File

@ -245,7 +245,7 @@ ts.addWidget({
ts.benchmark("Applying " + theme + " theme", time); ts.benchmark("Applying " + theme + " theme", time);
} }
}, },
remove: function(table, c) { remove: function(table, c, wo) {
var $table = c.$table, var $table = c.$table,
theme = c.theme || 'jui', theme = c.theme || 'jui',
themes = ts.themes[ theme ] || ts.themes.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_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_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_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_external : '', // jQuery selector string (or jQuery object) of external filters
filter_filteredRow : 'filtered', // class added to filtered rows; needed by pager plugin filter_filteredRow : 'filtered', // class added to filtered rows; needed by pager plugin
filter_formatter : null, // add custom filter elements to the filter row filter_formatter : null, // add custom filter elements to the filter row
@ -411,25 +410,24 @@ ts.filter = {
type : /undefined|number/, // check type type : /undefined|number/, // check type
exact : /(^[\"|\'|=]+)|([\"|\'|=]+$)/g, // exact match (allow '==') exact : /(^[\"|\'|=]+)|([\"|\'|=]+$)/g, // exact match (allow '==')
nondigit : /[^\w,. \-()]/g, // replace non-digits (from digit & currency parser) nondigit : /[^\w,. \-()]/g, // replace non-digits (from digit & currency parser)
operators : /[<>=]/g, // replace operators operators : /[<>=]/g // replace operators
query : /\{query\}/i // replace filter queries
}, },
// function( c, data ) { } // function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed )
// c = table.config // filter = array of filter input values; iFilter = same array, except lowercase
// data.filter = array of filter input values; data.iFilter = same array, except lowercase // exact = table cell text (or parsed data if column parser enabled)
// data.exact = table cell text (or parsed data if column parser enabled) // iExact = same as exact, except lowercase
// data.iExact = same as data.exact, except lowercase // cached = table cell text from cache, so it has been parsed
// data.cached = table cell text from cache, so it has been parsed // index = column index; table = table element (DOM)
// data.index = column index; table = table element (DOM) // wo = widget options (table.config.widgetOptions)
// data.parsed = array (by column) of boolean values (from filter_useParsedData or "filter-parsed" class) // parsed = array (by column) of boolean values (from filter_useParsedData or "filter-parsed" class)
types: { types: {
// Look for regex // Look for regex
regex: function( c, data ) { regex: function( filter, iFilter, exact, iExact ) {
if ( ts.filter.regex.regex.test(data.iFilter) ) { if ( ts.filter.regex.regex.test(iFilter) ) {
var matches, var matches,
regex = ts.filter.regex.regex.exec(data.iFilter); regex = ts.filter.regex.regex.exec(iFilter);
try { try {
matches = new RegExp(regex[1], regex[2]).test( data.iExact ); matches = new RegExp(regex[1], regex[2]).test( iExact );
} catch (error) { } catch (error) {
matches = false; matches = false;
} }
@ -438,29 +436,27 @@ ts.filter = {
return null; return null;
}, },
// Look for operators >, >=, < or <= // Look for operators >, >=, < or <=
operators: function( c, data ) { operators: function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) {
if ( /^[<>]=?/.test(data.iFilter) ) { if ( /^[<>]=?/.test(iFilter) ) {
var cachedValue, result, var cachedValue, result,
table = c.table, c = table.config,
index = data.index, query = ts.formatFloat( iFilter.replace(ts.filter.regex.operators, ''), table ),
parsed = data.parsed[index],
query = ts.formatFloat( data.iFilter.replace(ts.filter.regex.operators, ''), table ),
parser = c.parsers[index], parser = c.parsers[index],
savedSearch = query; savedSearch = query;
// parse filter value in case we're comparing numbers (dates) // parse filter value in case we're comparing numbers (dates)
if (parsed || parser.type === 'numeric') { if (parsed[index] || parser.type === 'numeric') {
result = ts.filter.parseFilter(c, $.trim('' + data.iFilter.replace(ts.filter.regex.operators, '')), index, parsed, true); 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; query = ( typeof result === "number" && result !== '' && !isNaN(result) ) ? result : query;
} }
// iExact may be numeric - see issue #149; // iExact may be numeric - see issue #149;
// check if cached is defined, because sometimes j goes out of range? (numeric columns) // 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 : cachedValue = ( parsed[index] || parser.type === 'numeric' ) && !isNaN(query) && typeof cached !== 'undefined' ? cached :
isNaN(data.iExact) ? ts.formatFloat( data.iExact.replace(ts.filter.regex.nondigit, ''), table) : isNaN(iExact) ? ts.formatFloat( iExact.replace(ts.filter.regex.nondigit, ''), table) :
ts.formatFloat( data.iExact, 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 ( /</.test(data.iFilter) ) { result = /<=/.test(data.iFilter) ? cachedValue <= query : cachedValue < query; } if ( /</.test(iFilter) ) { result = /<=/.test(iFilter) ? cachedValue <= query : cachedValue < query; }
// keep showing all rows if nothing follows the operator // keep showing all rows if nothing follows the operator
if ( !result && savedSearch === '' ) { result = true; } if ( !result && savedSearch === '' ) { result = true; }
return result; return result;
@ -468,40 +464,37 @@ ts.filter = {
return null; return null;
}, },
// Look for a not match // Look for a not match
notMatch: function( c, data ) { notMatch: function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) {
if ( /^\!/.test(data.iFilter) ) { if ( /^\!/.test(iFilter) ) {
var indx, iFilter = ts.filter.parseFilter(table, iFilter.replace('!', ''), index, parsed[index]);
filter = ts.filter.parseFilter(c, data.iFilter.replace('!', ''), data.index, data.parsed[data.index]); if (ts.filter.regex.exact.test(iFilter)) {
if (ts.filter.regex.exact.test(filter)) {
// look for exact not matches - see #628 // look for exact not matches - see #628
filter = filter.replace(ts.filter.regex.exact, ''); iFilter = iFilter.replace(ts.filter.regex.exact, '');
return filter === '' ? true : $.trim(filter) !== data.iExact; return iFilter === '' ? true : $.trim(iFilter) !== iExact;
} else { } else {
indx = data.iExact.search( $.trim(filter) ); var indx = iExact.search( $.trim(iFilter) );
return filter === '' ? true : !(c.widgetOptions.filter_startsWith ? indx === 0 : indx >= 0); return iFilter === '' ? true : !(wo.filter_startsWith ? indx === 0 : indx >= 0);
} }
} }
return null; return null;
}, },
// Look for quotes or equals to get an exact match; ignore type since iExact could be numeric // 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 */ /*jshint eqeqeq:false */
if (ts.filter.regex.exact.test(data.iFilter)) { if (ts.filter.regex.exact.test(iFilter)) {
var filter = ts.filter.parseFilter(c, data.iFilter.replace(ts.filter.regex.exact, ''), data.index, data.parsed[data.index]); var fltr = ts.filter.parseFilter(table, iFilter.replace(ts.filter.regex.exact, ''), index, parsed[index]);
return data.anyMatch ? $.inArray(filter, data.rowArray) >= 0 : filter == data.iExact; return rowArray ? $.inArray(fltr, rowArray) >= 0 : fltr == iExact;
} }
return null; return null;
}, },
// Look for an AND or && operator (logical and) // Look for an AND or && operator (logical and)
and : function( c, data ) { and : function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) {
if ( ts.filter.regex.andTest.test(data.filter) ) { if ( ts.filter.regex.andTest.test(filter) ) {
var index = data.index, var query = iFilter.split( ts.filter.regex.andSplit ),
parsed = data.parsed[index], result = iExact.search( $.trim(ts.filter.parseFilter(table, query[0], index, parsed[index])) ) >= 0,
query = data.iFilter.split( ts.filter.regex.andSplit ),
result = data.iExact.search( $.trim( ts.filter.parseFilter(c, query[0], index, parsed) ) ) >= 0,
indx = query.length - 1; indx = query.length - 1;
while (result && indx) { 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--; indx--;
} }
return result; return result;
@ -509,55 +502,52 @@ ts.filter = {
return null; return null;
}, },
// Look for a range (using " to " or " - ") - see issue #166; thanks matzhu! // Look for a range (using " to " or " - ") - see issue #166; thanks matzhu!
range : function( c, data ) { range : function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) {
if ( ts.filter.regex.toTest.test(data.iFilter) ) { if ( ts.filter.regex.toTest.test(iFilter) ) {
var result, tmp, var result, tmp,
table = c.table, c = table.config,
index = data.index,
parsed = data.parsed[index],
// make sure the dash is for a range and not indicating a negative number // make sure the dash is for a range and not indicating a negative number
query = data.iFilter.split( ts.filter.regex.toSplit ), query = iFilter.split( ts.filter.regex.toSplit ),
range1 = ts.formatFloat( ts.filter.parseFilter(c, query[0].replace(ts.filter.regex.nondigit, ''), index, parsed), table ), range1 = ts.formatFloat( ts.filter.parseFilter(table, query[0].replace(ts.filter.regex.nondigit, ''), index, parsed[index]), table ),
range2 = ts.formatFloat( ts.filter.parseFilter(c, query[1].replace(ts.filter.regex.nondigit, ''), index, parsed), 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) // 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); result = c.parsers[index].format('' + query[0], table, c.$headers.eq(index), index);
range1 = (result !== '' && !isNaN(result)) ? result : range1; range1 = (result !== '' && !isNaN(result)) ? result : range1;
result = c.parsers[index].format('' + query[1], table, c.$headers.eq(index), index); result = c.parsers[index].format('' + query[1], table, c.$headers.eq(index), index);
range2 = (result !== '' && !isNaN(result)) ? result : range2; range2 = (result !== '' && !isNaN(result)) ? result : range2;
} }
result = ( parsed || c.parsers[index].type === 'numeric' ) && !isNaN(range1) && !isNaN(range2) ? data.cached : result = ( parsed[index] || c.parsers[index].type === 'numeric' ) && !isNaN(range1) && !isNaN(range2) ? cached :
isNaN(data.iExact) ? ts.formatFloat( data.iExact.replace(ts.filter.regex.nondigit, ''), table) : isNaN(iExact) ? ts.formatFloat( iExact.replace(ts.filter.regex.nondigit, ''), table) :
ts.formatFloat( data.iExact, table ); ts.formatFloat( iExact, table );
if (range1 > range2) { tmp = range1; range1 = range2; range2 = tmp; } // swap if (range1 > range2) { tmp = range1; range1 = range2; range2 = tmp; } // swap
return (result >= range1 && result <= range2) || (range1 === '' || range2 === ''); return (result >= range1 && result <= range2) || (range1 === '' || range2 === '');
} }
return null; return null;
}, },
// Look for wild card: ? = single, * = multiple, or | = logical OR // Look for wild card: ? = single, * = multiple, or | = logical OR
wild : function( c, data ) { wild : function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed, rowArray ) {
if ( /[\?|\*]/.test(data.iFilter) || ts.filter.regex.orReplace.test(data.filter) ) { if ( /[\?|\*]/.test(iFilter) || ts.filter.regex.orReplace.test(filter) ) {
var index = data.index, var c = table.config,
parsed = data.parsed[index], query = ts.filter.parseFilter(table, iFilter.replace(ts.filter.regex.orReplace, "|"), index, parsed[index]);
query = ts.filter.parseFilter(c, data.iFilter.replace(ts.filter.regex.orReplace, "|"), index, parsed);
// look for an exact match with the "or" unless the "filter-match" class is found // 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)) { 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 =/ // 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; return null;
}, },
// fuzzy text search; modified from https://github.com/mattyork/fuzzy (MIT license) // fuzzy text search; modified from https://github.com/mattyork/fuzzy (MIT license)
fuzzy: function( c, data ) { fuzzy: function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) {
if ( /^~/.test(data.iFilter) ) { if ( /^~/.test(iFilter) ) {
var indx, var indx,
patternIndx = 0, patternIndx = 0,
len = data.iExact.length, len = iExact.length,
pattern = ts.filter.parseFilter(c, data.iFilter.slice(1), data.index, data.parsed[data.index]); pattern = ts.filter.parseFilter(table, iFilter.slice(1), index, parsed[index]);
for (indx = 0; indx < len; indx++) { for (indx = 0; indx < len; indx++) {
if (data.iExact[indx] === pattern[patternIndx]) { if (iExact[indx] === pattern[patternIndx]) {
patternIndx += 1; patternIndx += 1;
} }
} }
@ -790,9 +780,10 @@ ts.filter = {
c.$table.data('lastSearch', filters); c.$table.data('lastSearch', filters);
return filters; return filters;
}, },
parseFilter: function(c, filter, column, parsed, forceParse){ parseFilter: function(table, filter, column, parsed, forceParse){
var c = table.config;
return forceParse || parsed ? return forceParse || parsed ?
c.parsers[column].format( filter, c.table, [], column ) : c.parsers[column].format( filter, table, [], column ) :
filter; filter;
}, },
buildRow: function(table, c, wo) { buildRow: function(table, c, wo) {
@ -1002,26 +993,24 @@ ts.filter = {
}, },
findRows: function(table, filters, combinedFilters) { findRows: function(table, filters, combinedFilters) {
if (table.config.lastCombinedFilter === combinedFilters) { return; } if (table.config.lastCombinedFilter === combinedFilters) { return; }
var len, $rows, rowIndex, tbodyIndex, $tbody, $cells, columnIndex, var cached, len, $rows, rowIndex, tbodyIndex, $tbody, $cells, columnIndex,
childRow, lastSearch, matches, result, showRow, time, val, indx, childRow, childRowText, exact, iExact, iFilter, lastSearch, matches, result,
query, notFiltered, searchFiltered, filterMatched, fxn, ffxn, notFiltered, searchFiltered, filterMatched, showRow, time, val, indx,
anyMatch, iAnyMatch, rowArray, rowText, iRowText, rowCache, fxn, ffxn,
regex = ts.filter.regex, regex = ts.filter.regex,
c = table.config, c = table.config,
wo = c.widgetOptions, wo = c.widgetOptions,
columns = c.columns,
$tbodies = c.$table.children('tbody'), // target all tbodies #568 $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 // anyMatch really screws up with these types of filters
noAnyMatch = [ 'range', 'notMatch', 'operators' ]; anyMatchNotAllowedTypes = [ 'range', 'notMatch', 'operators' ],
// parse columns after formatter, in case the class is added at that point
// parse columns after formatter, in case the class is added at that point parsed = c.$headers.map(function(columnIndex) {
data.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'), ts.getColumnData( table, 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(); }
// filtered rows count // filtered rows count
c.filteredRows = 0; c.filteredRows = 0;
@ -1071,21 +1060,12 @@ ts.filter = {
ts.log( "Searching through " + ( searchFiltered && notFiltered < len ? notFiltered : "all" ) + " rows" ); ts.log( "Searching through " + ( searchFiltered && notFiltered < len ? notFiltered : "all" ) + " rows" );
} }
if ((wo.filter_$anyMatch && wo.filter_$anyMatch.length) || filters[c.columns]) { if ((wo.filter_$anyMatch && wo.filter_$anyMatch.length) || filters[c.columns]) {
data.anyMatch = true; anyMatch = wo.filter_$anyMatch && wo.filter_$anyMatch.val() || filters[c.columns] || '';
data.filter = wo.filter_$anyMatch && wo.filter_$anyMatch.val() || filters[c.columns] || '';
if (c.sortLocaleCompare) { if (c.sortLocaleCompare) {
// replace accents // replace accents
data.filter = ts.replaceAccents(data.filter); anyMatch = ts.replaceAccents(anyMatch);
} }
if (regex.query.test(wo.filter_defaultType[c.columns] || '')) { iAnyMatch = anyMatch.toLowerCase();
query = data.filter.split(/\s/);
val = wo.filter_defaultType[c.columns];
for (indx = 0; indx < query.length; indx++) {
val = val.replace(regex.query, query[indx]);
}
data.filter = val;
}
data.iFilter = data.filter.toLowerCase();
} }
// loop through the rows // loop through the rows
for (rowIndex = 0; rowIndex < len; rowIndex++) { for (rowIndex = 0; rowIndex < len; rowIndex++) {
@ -1098,14 +1078,14 @@ ts.filter = {
// so, if "table.config.widgetOptions.filter_childRows" is true and there is // so, if "table.config.widgetOptions.filter_childRows" is true and there is
// a match anywhere in the child row, then it will make the row visible // a match anywhere in the child row, then it will make the row visible
// checked here so the option can be changed dynamically // checked here so the option can be changed dynamically
data.childRowText = (childRow.length && wo.filter_childRows) ? childRow.text() : ''; childRowText = (childRow.length && wo.filter_childRows) ? childRow.text() : '';
data.childRowText = wo.filter_ignoreCase ? data.childRowText.toLocaleLowerCase() : data.childRowText; childRowText = wo.filter_ignoreCase ? childRowText.toLocaleLowerCase() : childRowText;
$cells = $rows.eq(rowIndex).children(); $cells = $rows.eq(rowIndex).children();
if (data.anyMatch) { if (anyMatch) {
data.rowArray = $cells.map(function(i){ rowArray = $cells.map(function(i){
var txt; var txt;
if (data.parsed[i]) { if (parsed[i]) {
txt = c.cache[tbodyIndex].normalized[rowIndex][i]; txt = c.cache[tbodyIndex].normalized[rowIndex][i];
} else { } else {
txt = wo.filter_ignoreCase ? $(this).text().toLowerCase() : $(this).text(); txt = wo.filter_ignoreCase ? $(this).text().toLowerCase() : $(this).text();
@ -1115,13 +1095,13 @@ ts.filter = {
} }
return txt; return txt;
}).get(); }).get();
data.exact = data.rowArray.join(' '); rowText = rowArray.join(' ');
data.iExact = data.exact.toLowerCase(); iRowText = rowText.toLowerCase();
data.cached = c.cache[tbodyIndex].normalized[rowIndex].slice(0,-1).join(' '); rowCache = c.cache[tbodyIndex].normalized[rowIndex].slice(0,-1).join(' ');
filterMatched = null; filterMatched = null;
$.each(ts.filter.types, function(type, typeFunction) { $.each(ts.filter.types, function(type, typeFunction) {
if ($.inArray(type, noAnyMatch) < 0) { if ($.inArray(type, anyMatchNotAllowedTypes) < 0) {
matches = typeFunction( c, data ); matches = typeFunction( anyMatch, iAnyMatch, rowText, iRowText, rowCache, columns, table, wo, parsed, rowArray );
if (matches !== null) { if (matches !== null) {
filterMatched = matches; filterMatched = matches;
return false; return false;
@ -1133,33 +1113,30 @@ ts.filter = {
} else { } else {
if (wo.filter_startsWith) { if (wo.filter_startsWith) {
showRow = false; showRow = false;
columnIndex = c.columns; columnIndex = columns;
while (!showRow && columnIndex > 0) { while (!showRow && columnIndex > 0) {
columnIndex--; columnIndex--;
showRow = showRow || data.rowArray[columnIndex].indexOf(data.iFilter) === 0; showRow = showRow || rowArray[columnIndex].indexOf(iAnyMatch) === 0;
} }
} else { } else {
showRow = (data.iExact + data.childRowText).indexOf(data.iFilter) >= 0; showRow = (iRowText + childRowText).indexOf(iAnyMatch) >= 0;
} }
} }
data.anyMatch = false;
} }
for (columnIndex = 0; columnIndex < c.columns; columnIndex++) { for (columnIndex = 0; columnIndex < columns; columnIndex++) {
data.filter = filters[columnIndex];
data.index = columnIndex;
// ignore if filter is empty or disabled // ignore if filter is empty or disabled
if (data.filter) { if (filters[columnIndex]) {
data.cached = c.cache[tbodyIndex].normalized[rowIndex][columnIndex]; cached = c.cache[tbodyIndex].normalized[rowIndex][columnIndex];
// check if column data should be from the cell or from parsed data // check if column data should be from the cell or from parsed data
if (wo.filter_useParsedData || data.parsed[columnIndex]) { if (wo.filter_useParsedData || parsed[columnIndex]) {
data.exact = data.cached; exact = cached;
} else { } else {
// using older or original tablesorter // using older or original tablesorter
data.exact = $.trim( $cells.eq(columnIndex).text() ); exact = $.trim($cells.eq(columnIndex).text());
data.exact = c.sortLocaleCompare ? ts.replaceAccents(data.exact) : data.exact; // issue #405 exact = c.sortLocaleCompare ? ts.replaceAccents(exact) : exact; // issue #405
} }
data.iExact = !regex.type.test(typeof data.exact) && wo.filter_ignoreCase ? data.exact.toLocaleLowerCase() : data.exact; iExact = !regex.type.test(typeof exact) && wo.filter_ignoreCase ? exact.toLocaleLowerCase() : exact;
result = showRow; // if showRow is true, show that row result = showRow; // if showRow is true, show that row
// in case select filter option has a different value vs text "a - z|A through Z" // in case select filter option has a different value vs text "a - z|A through Z"
@ -1167,28 +1144,28 @@ ts.filter = {
c.$filters.add(c.$externalFilters).filter('[data-column="'+ columnIndex + '"]').find('select option:selected').attr('data-function-name') || '' : ''; c.$filters.add(c.$externalFilters).filter('[data-column="'+ columnIndex + '"]').find('select option:selected').attr('data-function-name') || '' : '';
// replace accents - see #357 // replace accents - see #357
data.filter = c.sortLocaleCompare ? ts.replaceAccents(data.filter) : data.filter; filters[columnIndex] = c.sortLocaleCompare ? ts.replaceAccents(filters[columnIndex]) : filters[columnIndex];
// val = case insensitive, columnFilter = case sensitive // val = case insensitive, filters[columnIndex] = case sensitive
data.iFilter = wo.filter_ignoreCase ? (data.filter || '').toLocaleLowerCase() : data.filter; iFilter = wo.filter_ignoreCase ? (filters[columnIndex] || '').toLocaleLowerCase() : filters[columnIndex];
fxn = ts.getColumnData( table, wo.filter_functions, columnIndex ); fxn = ts.getColumnData( table, wo.filter_functions, columnIndex );
if (fxn) { if (fxn) {
if (fxn === true) { if (fxn === true) {
// default selector; no "filter-select" class // default selector; no "filter-select" class
result = (c.$headers.filter('[data-column="' + columnIndex + '"]:last').hasClass('filter-match')) ? result = (c.$headers.filter('[data-column="' + columnIndex + '"]:last').hasClass('filter-match')) ?
data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact; iExact.search(iFilter) >= 0 : filters[columnIndex] === exact;
} else if (typeof fxn === 'function') { } else if (typeof fxn === 'function') {
// filter callback( exact cell content, parser normalized content, filter input value, column index, jQuery row object ) // filter callback( exact cell content, parser normalized content, filter input value, column index, jQuery row object )
result = fxn(data.exact, data.cached, data.filter, columnIndex, $rows.eq(rowIndex)); result = fxn(exact, cached, filters[columnIndex], columnIndex, $rows.eq(rowIndex));
} else if (typeof fxn[ffxn || data.filter] === 'function') { } else if (typeof fxn[ffxn || filters[columnIndex]] === 'function') {
// selector option function // selector option function
result = fxn[ffxn || data.filter](data.exact, data.cached, data.filter, columnIndex, $rows.eq(rowIndex)); result = fxn[ffxn || filters[columnIndex]](exact, cached, filters[columnIndex], columnIndex, $rows.eq(rowIndex));
} }
} else { } else {
filterMatched = null; filterMatched = null;
// cycle through the different filters // cycle through the different filters
// filters return a boolean or null if nothing matches // filters return a boolean or null if nothing matches
$.each(ts.filter.types, function(type, typeFunction) { $.each(ts.filter.types, function(type, typeFunction) {
matches = typeFunction( c, data ); matches = typeFunction( filters[columnIndex], iFilter, exact, iExact, cached, columnIndex, table, wo, parsed );
if (matches !== null) { if (matches !== null) {
filterMatched = matches; filterMatched = matches;
return false; return false;
@ -1198,8 +1175,8 @@ ts.filter = {
result = filterMatched; result = filterMatched;
// Look for match, and add child row data for matching // Look for match, and add child row data for matching
} else { } else {
data.exact = (data.iExact + data.childRowText).indexOf( ts.filter.parseFilter(c, data.iFilter, columnIndex, data.parsed[columnIndex]) ); exact = (iExact + childRowText).indexOf( ts.filter.parseFilter(table, iFilter, columnIndex, parsed[columnIndex]) );
result = ( (!wo.filter_startsWith && data.exact >= 0) || (wo.filter_startsWith && data.exact === 0) ); result = ( (!wo.filter_startsWith && exact >= 0) || (wo.filter_startsWith && exact === 0) );
} }
} }
showRow = (result) ? showRow : false; showRow = (result) ? showRow : false;

View File

@ -128,7 +128,7 @@
column = $this.closest('td').index(); column = $this.closest('td').index();
if ( e.which === 27 ) { if ( e.which === 27 ) {
// user cancelled // user cancelled
$this.html( $this.data('original') ).trigger('blur.tseditable'); $this.html( $.trim( $this.data('original') ) ).trigger('blur.tseditable');
c.$table.data( 'contentFocused', false ); c.$table.data( 'contentFocused', false );
return false; return false;
} }
@ -149,7 +149,7 @@
c.$table.find('.tseditable-last-edited-cell').removeClass('tseditable-last-edited-cell'); c.$table.find('.tseditable-last-edited-cell').removeClass('tseditable-last-edited-cell');
$this $this
.addClass('tseditable-last-edited-cell') .addClass('tseditable-last-edited-cell')
.html( valid ) .html( $.trim( valid ) )
.data('before', valid) .data('before', valid)
.data('original', valid) .data('original', valid)
.trigger('change'); .trigger('change');
@ -174,7 +174,7 @@
} }
}, 100)); }, 100));
// restore original content on blur // restore original content on blur
$this.html( $this.data('original') ); $this.html( $.trim( $this.data('original') ) );
} }
}); });
} }