Filter widget: make operator matching higher priority than exact matching. Fixes #465

This commit is contained in:
Mottie 2013-12-17 15:54:46 -06:00
parent d1a9f2ee22
commit 05d2075cef
2 changed files with 18 additions and 18 deletions

View File

@ -220,7 +220,7 @@ $(function(){
</tbody>
</table>
<span class="bright">(1)</span> You cannot combine these operators with each other (except for the wildcards).<br>
<span class="bright">(2)</span> The filter order (or precendence) of how searches are checked is as follows: <span class="smallcode">regex (<code>/\d/</code>) <strong>&gt;</strong> exact (<code>"</code>) <strong>&gt;</strong> not match (<code>!</code>) <strong>&gt;</strong> operators (<code>&lt; &lt;= &gt;= &gt;</code>) <strong>&gt;</strong> and (<code>&nbsp;AND&nbsp;</code>) <strong>&gt;</strong> range (<code>&nbsp;-&nbsp;</code>) <strong>&gt;</strong> wild/or (<code>?</code>, <code>*</code> and <code>&nbsp;OR&nbsp;</code>) <strong>&gt;</strong> fuzzy (<code>~</code>); so an exact match will override "and", "or" and "range" searches </span><br>
<span class="bright">(2)</span> The filter order (or precendence) of how searches are checked is as follows: <span class="smallcode">regex (<code>/\d/</code>) <strong>&gt;</strong> operators (<code>&lt; &lt;= &gt;= &gt;</code>) <strong>&gt;</strong> exact (<code>"</code>) <strong>&gt;</strong> not match (<code>!</code>) <strong>&gt;</strong> and (<code>&nbsp;AND&nbsp;</code>) <strong>&gt;</strong> range (<code>&nbsp;-&nbsp;</code>) <strong>&gt;</strong> wild/or (<code>?</code>, <code>*</code> and <code>&nbsp;OR&nbsp;</code>) <strong>&gt;</strong> fuzzy (<code>~</code>); so an exact match will override "and", "or" and "range" searches </span> (*NOTE* order changed in <span class="version">v2.14.6</span>, operators prioritized before exact; see <a href="https://github.com/Mottie/tablesorter/issues/465">issue #465</a>) <br>
<span class="bright">(3)</span> Logical "or" comparisons can now show exact matches (by default; <span class="version">v2.10.1</span>) or just match cell contents.<br>
<span class="bright">(4)</span> In tablesorter <span class="version">v2.10</span>, comparisons can be made in date columns (if properly parsed).
</li>

View File

@ -419,23 +419,6 @@ ts.filter = {
}
return null;
},
// Look for quotes or equals to get an exact match; ignore type since iExact could be numeric
exact: function( filter, iFilter, exact, iExact ) {
/*jshint eqeqeq:false */
if (ts.filter.regex.exact.test(iFilter)) {
return iFilter.replace(ts.filter.regex.exact, '') == iExact;
}
return null;
},
// Look for a not match
notMatch: function( filter, iFilter, exact, iExact, cached, index, table, wo ) {
if ( /^\!/.test(iFilter) ) {
iFilter = iFilter.replace('!', '');
var indx = iExact.search( $.trim(iFilter) );
return iFilter === '' ? true : !(wo.filter_startsWith ? indx === 0 : indx >= 0);
}
return null;
},
// Look for operators >, >=, < or <=
operators: function( filter, iFilter, exact, iExact, cached, index, table, wo, parsed ) {
if ( /^[<>]=?/.test(iFilter) ) {
@ -462,6 +445,23 @@ ts.filter = {
}
return null;
},
// Look for quotes or equals to get an exact match; ignore type since iExact could be numeric
exact: function( filter, iFilter, exact, iExact ) {
/*jshint eqeqeq:false */
if (ts.filter.regex.exact.test(iFilter)) {
return iFilter.replace(ts.filter.regex.exact, '') == iExact;
}
return null;
},
// Look for a not match
notMatch: function( filter, iFilter, exact, iExact, cached, index, table, wo ) {
if ( /^\!/.test(iFilter) ) {
iFilter = iFilter.replace('!', '');
var indx = iExact.search( $.trim(iFilter) );
return iFilter === '' ? true : !(wo.filter_startsWith ? indx === 0 : indx >= 0);
}
return null;
},
// Look for an AND or && operator (logical and)
and : function( filter, iFilter, exact, iExact ) {
if ( /\s+(AND|&&)\s+/g.test(filter) ) {