Filter: anymatch now uses filter_ignoreCase option properly. Fixes #748

This commit is contained in:
Mottie 2014-10-21 12:18:43 -05:00
parent df36ae331d
commit fd038ceebe
2 changed files with 18 additions and 11 deletions

View File

@ -30,9 +30,10 @@
</script> </script>
<script id="js">// *** Filter search type function arguments *** <script id="js">// *** Filter search type function arguments ***
// data.filter = filter input value for a column; iFilter = same as filter, except lowercase // data.filter = filter input value for a column;
// iFilter = same as filter, except lowercase (if wo.filter_ignoreCase is true)
// data.exact = table cell text (or parsed data, if column parser enabled) // data.exact = table cell text (or parsed data, if column parser enabled)
// data.iExact = same as exact, except lowercase // data.iExact = same as exact, except lowercase (if wo.filter_ignoreCase is true)
// search for a match from the beginning of a string // search for a match from the beginning of a string
// "^l" matches "lion" but not "koala" // "^l" matches "lion" but not "koala"
@ -153,9 +154,9 @@ $(function() {
<li>The following arguments are passed to the filter function within the <code>data</code> parameter (changed in <span class="version updated">v2.17.8</span>): <li>The following arguments are passed to the filter function within the <code>data</code> parameter (changed in <span class="version updated">v2.17.8</span>):
<ul> <ul>
<li><code>data.filter</code> - The exact text from the filter input (e.g. <code>^h</code>).</li> <li><code>data.filter</code> - The exact text from the filter input (e.g. <code>^h</code>).</li>
<li><code>data.iFilter</code> - The text from the filter in all lower case for case insensitive searches.</li> <li><code>data.iFilter</code> - The text from the filter in all lower case for case insensitive searches, if <code>table.config.widgetOptions.filter_ignoreCase</code> is <code>true</code>.</li>
<li><code>data.exact</code> - The exact (or parsed) text from the current table cell, or the entire row if <code>data.anyMatch</code> is <code>true</code>; the parsed text is passed when the column has a <code>"filter-parsed"</code> class name set.</li> <li><code>data.exact</code> - The exact (or parsed) text from the current table cell, or the entire row if <code>data.anyMatch</code> is <code>true</code>; the parsed text is passed when the column has a <code>"filter-parsed"</code> class name set.</li>
<li><code>data.iExact</code> - The exact (or parsed) text in all lower case for case insensitive searches.<br><br></li> <li><code>data.iExact</code> - The exact (or parsed) text in all lower case for case insensitive searches, if <code>table.config.widgetOptions.filter_ignoreCase</code> is <code>true</code>.<br><br></li>
<li><code>data.index</code> - The current column index (zero-based) being filtered. When performing an "any match", this index is equal to <code>config.columns</code> which is the last column of the table plus one.</li> <li><code>data.index</code> - The current column index (zero-based) being filtered. When performing an "any match", this index is equal to <code>config.columns</code> which is the last column of the table plus one.</li>
<li><code>data.cache</code> - The parsed text from the current table cell, or the entire row if <code>data.anyMatch</code> is <code>true</code>. This value will be in all lower case if <code>config.ignoreCase</code> is <code>true</code>.<br><br></li> <li><code>data.cache</code> - The parsed text from the current table cell, or the entire row if <code>data.anyMatch</code> is <code>true</code>. This value will be in all lower case if <code>config.ignoreCase</code> is <code>true</code>.<br><br></li>
@ -165,12 +166,15 @@ $(function() {
<li><code>data.cacheArray</code> - An array of parsed text from each table cell.</li> <li><code>data.cacheArray</code> - An array of parsed text from each table cell.</li>
<li><code>data.childRowText</code> - contains all text from any associated child rows.</li> <li><code>data.childRowText</code> - contains all text from any associated child rows.</li>
<li><code>data.parsed</code> - An array of boolean flags that indicate if the column data should obtained from parsed values, or not; obtained from <code>filter_useParsedData</code> setting or <code>filter-parsed</code> classes on the header cells.</li> <li><code>data.parsed</code> - An array of boolean flags that indicate if the column data should obtained from parsed values, or not; obtained from <code>filter_useParsedData</code> setting or <code>filter-parsed</code> classes on the header cells.<br>
<span class="label label-info">Note</span> Be aware that the values in this array will all be in lower case if the <code>table.config.ignoreCase</code> option is <code>true</code>.
</li>
</ul> </ul>
<br> <br>
</li> </li>
<li>If your designator doesn't exist, you *must* return <code>null</code> to allow comparisons with other filter types.</li> <li>If your designator doesn't exist, you *must* return <code>null</code> to allow comparisons with other filter types.</li>
</ul> </ul>
<br>
</li> </li>
<li>Here is a basic example with extensive comments: <li>Here is a basic example with extensive comments:
<pre class="prettyprint lang-js">// search for a match from the beginning of a string <pre class="prettyprint lang-js">// search for a match from the beginning of a string

View File

@ -422,10 +422,11 @@ ts.filter = {
}, },
// function( c, data ) { } // function( c, data ) { }
// c = table.config // c = table.config
// data.filter = array of filter input values; data.iFilter = same array, except lowercase // data.filter = array of filter input values;
// data.iFilter = same array, except lowercase (if wo.filter_ignoreCase is true)
// data.exact = table cell text (or parsed data if column parser enabled) // data.exact = table cell text (or parsed data if column parser enabled)
// data.iExact = same as data.exact, except lowercase // data.iExact = same as data.exact, except lowercase (if wo.filter_ignoreCase is true)
// data.cache = table cell text from cache, so it has been parsed // data.cache = table cell text from cache, so it has been parsed (& in all lower case if config.ignoreCase is true)
// data.index = column index; table = table element (DOM) // data.index = column index; table = table element (DOM)
// data.parsed = array (by column) of boolean values (from filter_useParsedData or "filter-parsed" class) // data.parsed = array (by column) of boolean values (from filter_useParsedData or "filter-parsed" class)
types: { types: {
@ -1168,7 +1169,9 @@ ts.filter = {
// clear search filtered flag because default filters are not saved to the last search // clear search filtered flag because default filters are not saved to the last search
searchFiltered = false; searchFiltered = false;
} }
data.iAnyMatchFilter = data.anyMatchFilter; // make iAnyMatchFilter lowercase unless both filter widget & core ignoreCase options are true
// when c.ignoreCase is true, the cache contains all lower case data
data.iAnyMatchFilter = !(wo.filter_ignoreCase && c.ignoreCase) ? data.anyMatchFilter : data.anyMatchFilter.toLocaleLowerCase();
} }
// loop through the rows // loop through the rows
@ -1209,7 +1212,7 @@ ts.filter = {
data.filter = data.anyMatchFilter; data.filter = data.anyMatchFilter;
data.iFilter = data.iAnyMatchFilter; data.iFilter = data.iAnyMatchFilter;
data.exact = data.rowArray.join(' '); data.exact = data.rowArray.join(' ');
data.iExact = data.exact.toLowerCase(); data.iExact = wo.filter_ignoreCase ? data.exact.toLowerCase() : data.exact;
data.cache = data.cacheArray.slice(0,-1).join(' '); data.cache = data.cacheArray.slice(0,-1).join(' ');
filterMatched = null; filterMatched = null;
$.each(ts.filter.types, function(type, typeFunction) { $.each(ts.filter.types, function(type, typeFunction) {
@ -1272,7 +1275,7 @@ ts.filter = {
// val is used to indicate that a filter select is using a default filter; so we override the exact & partial matches // val is used to indicate that a filter select is using a default filter; so we override the exact & partial matches
val = false; val = false;
} }
// data.iFilter = case insensitive, data.filter = case sensitive // data.iFilter = case insensitive (if wo.filter_ignoreCase is true), data.filter = case sensitive
data.iFilter = wo.filter_ignoreCase ? (data.filter || '').toLocaleLowerCase() : data.filter; data.iFilter = wo.filter_ignoreCase ? (data.filter || '').toLocaleLowerCase() : data.filter;
fxn = ts.getColumnData( table, wo.filter_functions, columnIndex ); fxn = ts.getColumnData( table, wo.filter_functions, columnIndex );
$cell = c.$headers.filter('[data-column="' + columnIndex + '"]:last'); $cell = c.$headers.filter('[data-column="' + columnIndex + '"]:last');