Filter: Remove not any match limitation

This commit is contained in:
Rob Garrison 2016-05-28 09:05:58 -05:00
parent 89be0907cb
commit b473f4f653
No known key found for this signature in database
GPG Key ID: 0A42D160D71978E1
5 changed files with 23 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -73,6 +73,7 @@
<h3><a href="#">Notes</a></h3>
<div>
<ul>
<li>In <span class="version updated">v2.26.2</span>, The not match (<code>!</code>) limitation is no longer in place. Try searching in the "Match any column" for <button type="button" data-column="all">!aaron</button>.
<li>In <span class="version">v2.22.0</span>, AnyMatch searches for specific columns will no longer save filter data to each targeted column. See the "AnyMatch Searches" section below.</li>
<li>In <span class="version">v2.20.0</span>, <a href="https://github.com/MaksimProgr">@MasksimProgr</a> added a method to allow targeting a specific column using the anyMatch filter. Find more details in the AnyMatch section below.</li>
<li>In <span class="version">v2.18.0</span>, the external search data column can be set to multiple columns (<code>data-column="0-2,4,6-7"</code>). Please see the <a href="example-widget-filter-external-inputs.html">Filter Widget External Inputs</a> demo for more details.</li>
@ -127,13 +128,17 @@
&quot;Fred&quot; &lt; 10 // false</pre>* For comparisons, letters have a greater <a href="http://en.wikipedia.org/wiki/Ascii#ASCII_printable_characters">ASCII value</a> than numbers.
</li>
<li>Range query - A search for any number range (<code>1 - 10</code>) is not allowed because, if any columns contain text, then no rows will result. The examples are the same as the search operators examples above.</li>
<li>Not Match query - A search for not matches (<code>!a</code>) is not allowed because tables that contain both numbers and text (in separate columns) will always show all rows. For example:
<li>Allowed filters include plain text matching, fuzzy search (<code>~</code>), exact match (<code>&quot;</code>), wild card matches( <code>?</code> or <code>*</code>), regex (<code>/\d/g</code>), and logical and (<code>a &amp;&amp; b</code>)/or (<code>a|b</code>) matches.<br><br></li>
<li>Not Match query - <strong>No longer a limitation!</strong> (<span class="version updated">v2.26.2</span>)
<p>Try searching for <button type="button" data-column="all">!aaron</button></p>
<del>A search for not matches (<code>!a</code>) is not allowed because tables that contain both numbers and text (in separate columns) will always show all rows. For example:
<pre class="prettyprint lang-javascript">&quot;Frank&quot;.search(&quot;a&quot;) // 2 (a match, so this row "may" be hidden)
&quot;Fred&quot;.search(&quot;a&quot;) // -1 (a not match! so this row will always show)
&quot;25&quot;.search(&quot;a&quot;) // -1 (a not match! so this row will always show)
&quot;1/1/2014&quot;.search(&quot;a&quot;) // -1 (a not match! so this row will always show)</pre>
&quot;1/1/2014&quot;.search(&quot;a&quot;) // -1 (a not match! so this row will always show)</pre></del>
</li>
<li>Allowed filters include plain text matching, fuzzy search (<code>~</code>), exact match (<code>&quot;</code>), wild card matches( <code>?</code> or <code>*</code>), regex (<code>/\d/g</code>), and logical and (<code>a &amp;&amp; b</code>)/or (<code>a|b</code>) matches.</li>
</ul>
</li>
<li>Setting this option should work properly with or without the column filters. The only issue you would have is if you triggered a search on the table using an array with undefined or null array values, like this:

View File

@ -461,7 +461,7 @@
<li><span class="results">&dagger;</span> Filter widget (<span class="version updated">v2.25.9</span>):
<ul>
<li><a href="example-widget-filter.html">basic</a> (v2.0.18; <span class="version updated">v2.25.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>
<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.26.2</span>).</li>
<li><a href="example-widget-filter-external-inputs.html">external inputs</a> (<span class="version">v2.14</span>; <span class="version updated">v2.18.0</span>).</li>
<li><a href="example-widget-filter-custom.html">custom filter functions</a> (v2.3.6; <span class="version updated">v2.22.0</span>).</li>
<li><a href="example-widget-filter-custom-search.html">custom search types</a> (<span class="version">v2.17.5</span>; <span class="version updated">v2.22.0</span>).</li>
@ -4747,7 +4747,7 @@ $('table').trigger('search', false);</pre></div>
<br>
This option has been replaced by the <a href="#widget-filter-external"><code>filter_external</code></a> option.<br>
<br>
Show any rows that match a search query. If this option is <code>true</code> any column match will show that row; but there are limitations (<span class="version">v2.13.3</span>).<br>
Show any rows that match a search query. If this option is <code>true</code> any column match will show that row; but <a href="example-widget-filter-any-match.html#limitations">there are limitations</a> (<span class="version">v2.13.3</span>).<br>
<br>
It is best if this <a href="#widget-filter-anymatch"><code>filter_anyMatch</code></a> option is used with a single search input as follows:
<pre class="prettyprint lang-html">&lt;input class=&quot;search&quot; type=&quot;search&quot;&gt;

View File

@ -1,4 +1,4 @@
/*! Widget: filter - updated 4/29/2016 (v2.25.9) *//*
/*! Widget: filter - updated 5/16/2015 (v2.26.1) *//*
* Requires tablesorter v2.8+ and jQuery 1.7+
* by Rob Garrison
*/
@ -262,7 +262,11 @@
return filter === '' ? true : $.trim( filter ) !== data.iExact;
} else {
indx = data.iExact.search( $.trim( filter ) );
return filter === '' ? true : !( c.widgetOptions.filter_startsWith ? indx === 0 : indx >= 0 );
return filter === '' ? true :
// return true if not found
data.anyMatch ? indx < 0 :
// return false if found
!( c.widgetOptions.filter_startsWith ? indx === 0 : indx >= 0 );
}
}
return null;
@ -1081,7 +1085,6 @@
// look for multiple columns '1-3,4-6,8'
tsf.multipleColumns( c, wo.filter_$anyMatch ) :
[];
data.$cells = data.$row.children();
if ( data.anyMatchFlag && columnIndex.length > 1 || data.anyMatchFilter ) {
data.anyMatch = true;
@ -1225,7 +1228,7 @@
},
vars = {
// anyMatch really screws up with these types of filters
noAnyMatch: [ 'range', 'notMatch', 'operators' ],
noAnyMatch: [ 'range', 'operators' ],
// cache filter variables that use ts.getColumnData in the main loop
functions : [],
excludeFilter : [],

View File

@ -197,7 +197,7 @@ jQuery(function($){
wo = this.wo,
$table = this.$table,
table = this.table;
expect(33);
expect(34);
return QUnit.SequentialRunner(
function(actions, assertions) {
@ -248,6 +248,9 @@ jQuery(function($){
).nextTask(
function(){ ts.setFilters( table, ['', '!aa'] ); },
function(){ assert.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 ); }
).nextTask(
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', '!3'] ); },
function(){ assert.cacheCompare( table, 0, [1, 11, 111, 9], 'search not any match', true ); }
).nextTask(
function(){ ts.setFilters( table, ['', 'br && c'] ); },
function(){ assert.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Bruce Lee'], 'search and match', true ); }