Filter: fix "or" test regex. Fixes #1117

This commit is contained in:
Rob Garrison 2016-01-10 21:03:55 -06:00
parent 1b57cdc141
commit d59befbbf3
3 changed files with 8 additions and 10 deletions

View File

@ -232,7 +232,7 @@ $(function(){
<ul>
<li>The <a class="intlink" href="#method-get-filters"><code>getFilters</code></a> function will now target the last used filter properly.</li>
<li>The <a class="intlink" href="#filter-select-source"><code>filter_selectSource</code></a> option now ignores parsers if none are set.</li>
<li>Added the ability to nest filter types with a logical "OR" or a logical "AND". Try these filters: <button data-filter-column="1">a && !o</button> (<span class="label warning">*NOTE*</span> try this with and without the filter-match class applied), <button data-filter-column="3">&lt10 or &gt;40</button> or <button data-filter-column="3">&gt;20 && &lt;40</button></li>
<li>Added the ability to nest filter types with a logical "OR" or a logical "AND". Try these filters: <button data-filter-column="1">a && !o</button> (<span class="label warning">*NOTE*</span> try this with and without the filter-match class applied), <button data-filter-column="3">&lt20 or &gt;40</button> or <button data-filter-column="3">&gt;20 && &lt;40</button></li>
</ul>
</li>
<li>In <span class="version">v2.22.0</span>
@ -290,7 +290,7 @@ $(function(){
</tr>
</thead>
<tbody>
<tr><td class="center">1</td><td class="center"><code>|</code> or <code>&nbsp;OR&nbsp;</code></td><td>Logical &quot;or&quot; (Vertical bar). Filter the column for content that matches text from either side of the bar <small class="bright">(2)</small>.</td><td><code>box|bat</code> (matches a column cell with either &quot;box&quot; or &quot;bat&quot;);<button data-filter-column="1">Alex|Peter</button> (Find text that contains either &quot;Alex&quot; or &quot;Peter&quot;); <button data-filter-column="3">&lt10 or &gt;40</button></td></tr>
<tr><td class="center">1</td><td class="center"><code>|</code> or <code>&nbsp;OR&nbsp;</code></td><td>Logical &quot;or&quot; (Vertical bar). Filter the column for content that matches text from either side of the bar <small class="bright">(2)</small>.</td><td><code>box|bat</code> (matches a column cell with either &quot;box&quot; or &quot;bat&quot;);<button data-filter-column="1">Alex|Peter</button> (Find text that contains either &quot;Alex&quot; or &quot;Peter&quot;); <button data-filter-column="3">&lt20 or &gt;40</button></td></tr>
<tr><td class="center">2</td><td class="center"><code>&nbsp;&&&nbsp;</code> or <code>&nbsp;AND&nbsp;</code></td><td>Logical &quot;and&quot;. Filter the column for content that matches text from either side of the operator.</td><td><code>box && bat</code> (matches a column cell that contains both &quot;box&quot; and &quot;bat&quot;), <button data-filter-column="1">Br && c</button> (Find text that contains both &quot;br&quot; and &quot;c&quot;), <button data-filter-column="3">&gt;20 && &lt;40</button> or <button data-filter-column="1">a and !o</button> (When "filter-match" is set, find content with the letter "a", but not the letter "o")</td></tr>
<tr><td class="center">3</td><td class="center"><code>/\d/</code></td><td>Add any regex to the query to use in the query ("mig" flags can be included <code>/\w/mig</code>)</td><td><code>/b[aeiou]g/i</code> (finds &quot;bag&quot;, &quot;beg&quot;, &quot;BIG&quot;, &quot;Bug&quot;, etc);<button data-filter-column="1">/r$/</button> (matches text that ends with an &quot;r&quot;)</td></tr>
<tr><td class="center">4</td><td class="center"><code>&lt; &lt;= &gt;= &gt;</code></td><td>Find alphabetical or numerical values less than or greater than or equal to the filtered query <small class="bright">(1)</small>.</td><td><button data-filter-column="5">&gt;= 10</button> (find values greater than or equal to 10)</td></tr>

View File

@ -458,7 +458,7 @@
<li><a href="example-widget-column-selector.html">Column selector widget</a> (<span class="version">v2.15</span>; <span class="version updated">v2.24.0</span>).</li>
<li><a href="example-widget-editable.html">Content editable widget</a> (v2.9; <span class="version updated">v2.25.0</span>).</li>
<li><span class="label label-info">Beta</span> <a href="example-dragtable.html">Dragtable mod</a> - (jQuery UI widget for column reordering [<a href="http://stackoverflow.com/a/27770224/145346">ref</a>]; <span class="version">v2.24.0</span>).</li>
<li><span class="results">&dagger;</span> Filter widget (<span class="version updated">v2.25.0</span>):
<li><span class="results">&dagger;</span> Filter widget (<span class="version updated">v2.25.1</span>):
<ul>
<li><a href="example-widget-filter.html">basic</a> (v2.0.18; <span class="version updated">v2.23.5</span>).</li>
<li><a href="example-widget-filter-any-match.html">external option (match any column)</a> (<span class="version">v2.13.3</span>; <span class="version updated">v2.22.0</span>).</li>

View File

@ -1,4 +1,4 @@
/*! Widget: filter - updated 12/13/2015 (v2.25.0) *//*
/*! Widget: filter - updated 1/10/2016 (v2.25.1) *//*
* Requires tablesorter v2.8+ and jQuery 1.7+
* by Rob Garrison
*/
@ -140,7 +140,7 @@
}
}
// may be null from processing types
return filterMatched || false;
return filterMatched;
}
return null;
},
@ -367,7 +367,7 @@
toSplit : new RegExp( '(?:\\s+(?:-|' + ts.language.to + ')\\s+)', 'gi' ),
andTest : new RegExp( '\\s+(' + ts.language.and + '|&&)\\s+', 'i' ),
andSplit : new RegExp( '(?:\\s+(?:' + ts.language.and + '|&&)\\s+)', 'gi' ),
orTest : /\|/,
orTest : new RegExp( '(\\||\\s+' + ts.language.or + '\\s+)', 'i' ),
orSplit : new RegExp( '(?:\\s+(?:' + ts.language.or + ')\\s+|\\|)', 'gi' ),
iQuery : new RegExp( val, 'i' ),
igQuery : new RegExp( val, 'ig' ),
@ -1048,7 +1048,6 @@
vars.excludeMatch = vars.noAnyMatch;
filterMatched = tsf.processTypes( c, data, vars );
if ( filterMatched !== null ) {
showRow = filterMatched;
} else {
@ -1142,8 +1141,7 @@
result = filterMatched;
// Look for match, and add child row data for matching
} else {
txt = ( data.iExact + data.childRowText )
.indexOf( tsf.parseFilter( c, data.iFilter, data ) );
txt = ( data.iExact + data.childRowText ).indexOf( tsf.parseFilter( c, data.iFilter, data ) );
result = ( ( !wo.filter_startsWith && txt >= 0 ) || ( wo.filter_startsWith && txt === 0 ) );
}
} else {
@ -1352,7 +1350,7 @@
// don't pass reference to val
val = showParent ? true : false;
childRow = rowData.$row.filter( ':gt( 0 )' );
childRow = rowData.$row.filter( ':gt(0)' );
if ( wo.filter_childRows && childRow.length ) {
if ( wo.filter_childByColumn ) {
if ( !wo.filter_childWithSibs ) {