| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Filter Widget</title> |
| 6 |
|
| 7 |
|
| 8 |
<script src="js/jquery-latest.min.js"></script> |
| 9 |
|
| 10 |
|
| 11 |
<link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css"> |
| 12 |
<script src="js/jquery-ui.min.js"></script> |
| 13 |
<link rel="stylesheet" href="css/jq.css"> |
| 14 |
<link href="css/prettify.css" rel="stylesheet"> |
| 15 |
<script src="js/prettify.js"></script> |
| 16 |
<script src="js/docs.js"></script> |
| 17 |
<style> |
| 18 |
/* override the vertical-align top in the blue theme */ |
| 19 |
.notes.tablesorter-blue tbody td { vertical-align: middle; } |
| 20 |
</style> |
| 21 |
|
| 22 |
|
| 23 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 24 |
<script src="../js/jquery.tablesorter.js"></script> |
| 25 |
<script src="../js/widgets/widget-storage.js"></script> |
| 26 |
<script src="../js/widgets/widget-filter.js"></script> |
| 27 |
|
| 28 |
<script id="js">$(function() { |
| 29 |
|
| 30 |
// call the tablesorter plugin |
| 31 |
$("#table").tablesorter({ |
| 32 |
theme: 'blue', |
| 33 |
|
| 34 |
// hidden filter input/selects will resize the columns, so try to minimize the change |
| 35 |
widthFixed : true, |
| 36 |
|
| 37 |
// initialize zebra striping and filter widgets |
| 38 |
widgets: ["zebra", "filter"], |
| 39 |
|
| 40 |
ignoreCase: false, |
| 41 |
|
| 42 |
widgetOptions : { |
| 43 |
|
| 44 |
// filter_anyMatch options was removed in v2.15; it has been replaced by the filter_external option |
| 45 |
|
| 46 |
// If there are child rows in the table (rows with class name from "cssChildRow" option) |
| 47 |
// and this option is true and a match is found anywhere in the child row, then it will make that row |
| 48 |
// visible; default is false |
| 49 |
filter_childRows : false, |
| 50 |
|
| 51 |
// if true, filter child row content by column; filter_childRows must also be true |
| 52 |
filter_childByColumn : false, |
| 53 |
|
| 54 |
// if true, include matching child row siblings |
| 55 |
filter_childWithSibs : true, |
| 56 |
|
| 57 |
// if true, a filter will be added to the top of each table column; |
| 58 |
// disabled by using -> headers: { 1: { filter: false } } OR add class="filter-false" |
| 59 |
// if you set this to false, make sure you perform a search using the second method below |
| 60 |
filter_columnFilters : true, |
| 61 |
|
| 62 |
// if true, allows using "#:{query}" in AnyMatch searches (column:query; added v2.20.0) |
| 63 |
filter_columnAnyMatch: true, |
| 64 |
|
| 65 |
// extra css class name (string or array) added to the filter element (input or select) |
| 66 |
filter_cellFilter : '', |
| 67 |
|
| 68 |
// extra css class name(s) applied to the table row containing the filters & the inputs within that row |
| 69 |
// this option can either be a string (class applied to all filters) or an array (class applied to indexed filter) |
| 70 |
filter_cssFilter : '', // or [] |
| 71 |
|
| 72 |
// add a default column filter type "~{query}" to make fuzzy searches default; |
| 73 |
// "{q1} AND {q2}" to make all searches use a logical AND. |
| 74 |
filter_defaultFilter : {}, |
| 75 |
|
| 76 |
// filters to exclude, per column |
| 77 |
filter_excludeFilter : {}, |
| 78 |
|
| 79 |
// jQuery selector (or object) pointing to an input to be used to match the contents of any column |
| 80 |
// please refer to the filter-any-match demo for limitations - new in v2.15 |
| 81 |
filter_external : '', |
| 82 |
|
| 83 |
// class added to filtered rows (rows that are not showing); needed by pager plugin |
| 84 |
filter_filteredRow : 'filtered', |
| 85 |
|
| 86 |
// ARIA-label added to filter input/select; {{label}} is replaced by the column header |
| 87 |
// "data-label" attribute, if it exists, or it uses the column header text |
| 88 |
filter_filterLabel : 'Filter "{{label}}" column by...', |
| 89 |
|
| 90 |
// add custom filter elements to the filter row |
| 91 |
// see the filter formatter demos for more specifics |
| 92 |
filter_formatter : null, |
| 93 |
|
| 94 |
// add custom filter functions using this option |
| 95 |
// see the filter widget custom demo for more specifics on how to use this option |
| 96 |
filter_functions : null, |
| 97 |
|
| 98 |
// hide filter row when table is empty |
| 99 |
filter_hideEmpty : true, |
| 100 |
|
| 101 |
// if true, filters are collapsed initially, but can be revealed by hovering over the grey bar immediately |
| 102 |
// below the header row. Additionally, tabbing through the document will open the filter row when an input gets focus |
| 103 |
// in v2.26.6, this option will also accept a function |
| 104 |
filter_hideFilters : true, |
| 105 |
|
| 106 |
// Set this option to false to make the searches case sensitive |
| 107 |
filter_ignoreCase : true, |
| 108 |
|
| 109 |
// if true, search column content while the user types (with a delay). |
| 110 |
// In v2.27.3, this option can contain an |
| 111 |
// object with column indexes or classnames; "fallback" is used |
| 112 |
// for undefined columns |
| 113 |
filter_liveSearch : true, |
| 114 |
|
| 115 |
// global query settings ('exact' or 'match'); overridden by "filter-match" or "filter-exact" class |
| 116 |
filter_matchType : { 'input': 'exact', 'select': 'exact' }, |
| 117 |
|
| 118 |
// a header with a select dropdown & this class name will only show available (visible) options within that drop down. |
| 119 |
filter_onlyAvail : 'filter-onlyAvail', |
| 120 |
|
| 121 |
// default placeholder text (overridden by any header "data-placeholder" setting) |
| 122 |
filter_placeholder : { search : '', select : '' }, |
| 123 |
|
| 124 |
// jQuery selector string of an element used to reset the filters |
| 125 |
filter_reset : 'button.reset', |
| 126 |
|
| 127 |
// Reset filter input when the user presses escape - normalized across browsers |
| 128 |
filter_resetOnEsc : true, |
| 129 |
|
| 130 |
// Use the $.tablesorter.storage utility to save the most recent filters (default setting is false) |
| 131 |
filter_saveFilters : true, |
| 132 |
|
| 133 |
// Delay in milliseconds before the filter widget starts searching; This option prevents searching for |
| 134 |
// every character while typing and should make searching large tables faster. |
| 135 |
filter_searchDelay : 300, |
| 136 |
|
| 137 |
// allow searching through already filtered rows in special circumstances; will speed up searching in large tables if true |
| 138 |
filter_searchFiltered: true, |
| 139 |
|
| 140 |
// include a function to return an array of values to be added to the column filter select |
| 141 |
filter_selectSource : null, |
| 142 |
|
| 143 |
// if true, server-side filtering should be performed because client-side filtering will be disabled, but |
| 144 |
// the ui and events will still be used. |
| 145 |
filter_serversideFiltering : false, |
| 146 |
|
| 147 |
// Set this option to true to use the filter to find text from the start of the column |
| 148 |
// So typing in "a" will find "albert" but not "frank", both have a's; default is false |
| 149 |
filter_startsWith : false, |
| 150 |
|
| 151 |
// Filter using parsed content for ALL columns |
| 152 |
// be careful on using this on date columns as the date is parsed and stored as time in seconds |
| 153 |
filter_useParsedData : false, |
| 154 |
|
| 155 |
// data attribute in the header cell that contains the default filter value |
| 156 |
filter_defaultAttrib : 'data-value', |
| 157 |
|
| 158 |
// filter_selectSource array text left of the separator is added to the option value, right into the option text |
| 159 |
filter_selectSourceSeparator : '|' |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
}); |
| 164 |
|
| 165 |
// Clear stored filters - added v2.25.6 |
| 166 |
$('.resetsaved').click(function() { |
| 167 |
$('#table').trigger('filterResetSaved'); |
| 168 |
|
| 169 |
// show quick popup to indicate something happened |
| 170 |
var $message = $('<span class="results"> Reset</span>').insertAfter(this); |
| 171 |
setTimeout(function() { |
| 172 |
$message.remove(); |
| 173 |
}, 500); |
| 174 |
return false; |
| 175 |
}); |
| 176 |
|
| 177 |
// External search |
| 178 |
// buttons set up like this: |
| 179 |
// <button type="button" data-filter-column="4" data-filter-text="2?%">Saved Search</button> |
| 180 |
$('button[data-filter-column]').click(function() { |
| 181 |
/*** first method *** data-filter-column="1" data-filter-text="!son" |
| 182 |
add search value to Discount column (zero based index) input */ |
| 183 |
var filters = [], |
| 184 |
$t = $(this), |
| 185 |
col = $t.data('filter-column'), // zero-based index |
| 186 |
txt = $t.data('filter-text') || $t.text(); // text to add to filter |
| 187 |
|
| 188 |
filters[col] = txt; |
| 189 |
// using "table.hasFilters" here to make sure we aren't targeting a sticky header |
| 190 |
$.tablesorter.setFilters( $('#table'), filters, true ); // new v2.9 |
| 191 |
|
| 192 |
/** old method (prior to tablsorter v2.9 *** |
| 193 |
var filters = $('table.tablesorter').find('input.tablesorter-filter'); |
| 194 |
filters.val(''); // clear all filters |
| 195 |
filters.eq(col).val(txt).trigger('search', false); |
| 196 |
******/ |
| 197 |
|
| 198 |
/*** second method *** |
| 199 |
this method bypasses the filter inputs, so the "filter_columnFilters" |
| 200 |
option can be set to false (no column filters showing) |
| 201 |
******/ |
| 202 |
/* |
| 203 |
var columns = []; |
| 204 |
columns[5] = '2?%'; // or define the array this way [ '', '', '', '', '', '2?%' ] |
| 205 |
$('table').trigger('search', [ columns ]); |
| 206 |
*/ |
| 207 |
|
| 208 |
return false; |
| 209 |
}); |
| 210 |
|
| 211 |
});</script> |
| 212 |
|
| 213 |
<script> |
| 214 |
$(function() { |
| 215 |
|
| 216 |
// *** widgetfilter_startsWith toggle button *** |
| 217 |
$('button.toggle').click(function() { |
| 218 |
var c = $('#table')[0].config, |
| 219 |
$t = $(this), |
| 220 |
// toggle the boolean |
| 221 |
fsw = !c.widgetOptions.filter_startsWith, |
| 222 |
fic = !c.widgetOptions.filter_ignoreCase; |
| 223 |
if ($t.hasClass('fsw')) { |
| 224 |
c.widgetOptions.filter_startsWith = fsw; |
| 225 |
$('#start').html(fsw.toString()); |
| 226 |
} else if ($t.hasClass('fic')) { |
| 227 |
c.widgetOptions.filter_ignoreCase = fic; |
| 228 |
$('#case').html(fic.toString()); |
| 229 |
} else { |
| 230 |
$t = c.$headers.eq(1).toggleClass('filter-match'); |
| 231 |
$t.find('span').html( $t.hasClass('filter-match') ? '' : ' No' ); |
| 232 |
} |
| 233 |
// update search after option change; add false to trigger to skip search delay |
| 234 |
c.$table.trigger('search', false); |
| 235 |
return false; |
| 236 |
}); |
| 237 |
|
| 238 |
}); |
| 239 |
</script> |
| 240 |
|
| 241 |
</head> |
| 242 |
<body> |
| 243 |
<div id="banner"> |
| 244 |
<h1>table<em>sorter</em></h1> |
| 245 |
<h2>Filter Widget</h2> |
| 246 |
<h3>Flexible client-side table sorting</h3> |
| 247 |
<a href="index.html">Back to documentation</a> |
| 248 |
</div> |
| 249 |
<div id="main"> |
| 250 |
|
| 251 |
<p></p> |
| 252 |
<br> |
| 253 |
<div id="root" class="accordion"> |
| 254 |
|
| 255 |
<h3 id="notes"><a href="#">Notes</a></h3> |
| 256 |
<div> |
| 257 |
<ul> |
| 258 |
<li>In <span class="version">v2.29.4</span>, <code>filter_filterLabel</code> option was added to include an ARIA-label to the filter inputs and selects.</li> |
| 259 |
<li>In <span class="verison">v2.27.3</span>, <code>filter_liveSearch</code> will now accept an object containing zero-based column indexes or header class names.</li> |
| 260 |
<li>In <span class="verison">v2.26.6</span>, the <a class="intlink" href="#filter-hidefilters"><code>hideFilters</code></a> setting will now accept a function to determine when to hide the filter row.</li> |
| 261 |
<li>In <span class="version">v2.25.6</span>, added <a class="intlink" href="#methods"><code>filterResetSaved</code></a> method to clear stored filter values.</li> |
| 262 |
<li>In <span class="version">v2.25.2</span>, added <a class="intlink" href="#filter-resetonesc"><code>filter_resetOnEsc</code></a> option.</li> |
| 263 |
<li>In <span class="version">v2.22.2</span>, |
| 264 |
<ul> |
| 265 |
<li>The <a class="intlink" href="#method-get-filters"><code>getFilters</code></a> function will now target the last used filter properly.</li> |
| 266 |
<li>The <a class="intlink" href="#filter-select-source"><code>filter_selectSource</code></a> option now ignores parsers if none are set.</li> |
| 267 |
<li>Added the ability to nest filter types with a logical "OR" or a logical "AND". Try these filters: <button type="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 type="button" data-filter-column="3"><20 or >40</button> or <button type="button" data-filter-column="3">>20 && <40</button></li> |
| 268 |
</ul> |
| 269 |
</li> |
| 270 |
</ul> |
| 271 |
|
| 272 |
<div class="accordion start-closed"> |
| 273 |
<h3 id="old-notes"><a href="#">Older Notes</a></h3> |
| 274 |
<div> |
| 275 |
<ul> |
| 276 |
<li>In <span class="version">v2.22.0</span> |
| 277 |
<ul> |
| 278 |
<li>Regex filter searches now cache the created regex object for each query to optimize speed & a regex search now properly uses case-sensitive content.</li> |
| 279 |
<li>Add <code>data</code> parameter to <a class="intlink" href="#filter-functions"><code>filter_functions</code></a> (<a href="example-widget-filter-custom-search.html#how_to_add_custom_filter_types">get more details</a>).</li> |
| 280 |
<li>Any match searches which target specific columns will no longer save each filter to its respective column; see <a href="example-widget-filter-any-match.html#anymatch_searches">"AnyMatch Searches"</a> documentation.</li> |
| 281 |
<li>Operator filter searchs now ignore empty strings (because <code>"" < 10</code> is <code>true</code>).</li> |
| 282 |
<li>Added <a class="intlink" href="#filter-child-by-column"><code>filter_childByColumn</code></a> option which allows the filtering columns in both the parent & child rows. Demo added to the <a href="example-child-rows-filtered.html#child-by-column">filtered child rows demo</a></li> |
| 283 |
</ul> |
| 284 |
</li> |
| 285 |
<li>In <span class="version updated">v2.18.0</span>, added <code>filter_cellFilter</code> & the ability to set multiple "any" match columns for an external search (see the <a href="example-widget-filter-external-inputs.html">external inputs demo</a> for more details).</li> |
| 286 |
<li>In <span class="version">v2.17.8</span>, filter selects will default to exact matches unless the header cell has a <a class="intlink" href="#classes"><code>"filter-match"</code></a> class added.</li> |
| 287 |
<li>In <span class="version">v2.17.1</span>, added a not exact match (<code>!=</code>) filter type.</li> |
| 288 |
<li>In <span class="version updated">v2.16+</span>, |
| 289 |
<ul> |
| 290 |
<li>When a default filter select is added to a column, it is now parsed from the assigned parser, then sorted using the <a href="index.html#textsorter"><code>textSorter</code></a> setting, and falls back to an alphanumeric sort (<span class="version updated">v2.16.3</span>).</li> |
| 291 |
<li>Adding a class of <a class="intlink" href="#classes"><code>"filter-select-nosort"</code></a> will now leave the select options unsorted (<span class="version">v2.16.3</span>).</li> |
| 292 |
<li>Added <a class="intlink" href="#filter-placeholder"><code>filter_placeholder</code></a> option (<span class="version">v2.16.0</span>).</li> |
| 293 |
<li>Added <a class="intlink" href="#filter-select-source"><code>filter_selectSource</code></a> option (<span class="version">v2.16.3</span>).</li> |
| 294 |
<li>updated <a class="intlink" href="#filter-reset"><code>filter_reset</code></a> option (<span class="version updated">v2.16.3</span>).</li> |
| 295 |
</ul> |
| 296 |
</li> |
| 297 |
<li>In <span class="version updated">v2.15</span>, |
| 298 |
<ul> |
| 299 |
<li>The <a class="intlink" href="#filter-any-match"><code>filter_anyMatch</code></a> widget option was completely <span class="label alert">removed</span>. Sorry for not deprecating this option, but the filter any match code was completely rewritten.</li> |
| 300 |
<li>Added a <a class="intlink" href="#filter-external"><code>filter_external</code></a> widget option to only accept a jQuery selector string/object; please see the updated <a href="example-widget-filter-any-match.html">filter any match</a> demo for more details.</li> |
| 301 |
</ul> |
| 302 |
</li> |
| 303 |
<li>Added & set <a class="intlink" href="#filter-save-filters"><code>filter_saveFilters</code></a> to <code>true</code> (default is <code>false</code>) in this demo (<span class="version">v2.14</span>).</li> |
| 304 |
</ul> |
| 305 |
</div> |
| 306 |
</div> |
| 307 |
|
| 308 |
<ul> |
| 309 |
<li><span class="label alert">*NOTE*</span> The filter widget is set to use extracted (parsed) content as parsed values and the raw cell content as unparsed values; and most of the time the filter is searching unparsed content (see <a class="intlink" href="#classes"><code>filter-parsed</code></a> class and <a class="intlink" href="#filter-use-parsed-data"><code>filter_useParsedData</code></a> option. But, when a data-attribute is used (see <a href="index.html#textattribute"><code>textAttribute</code></a> option), both the parsed and raw cached data will contain the <em>exact same content</em> (<a href="https://github.com/Mottie/tablesorter/issues/983">ref</a>)!</li> |
| 310 |
<li><span class="label alert">*NOTE*</span> If using a custom theme, make sure to add the class set in the <a class="intlink" href="#filter-filtered-row"><code>filter_filteredRow</code></a> option (set to <code>filtered</code> by default) in the css, and set it to <code>display:none</code>. When filtering rows, the filter widget adds the <a class="intlink" href="#filter-filtered-row"><code>"filtered"</code></a> class to hide the row; all available themes include this definition.</li> |
| 311 |
<li>Hover over the grey bar below the table header to open the filter row. Disable this by setting <a class="intlink" href="#filter-hide-filters"><code>filter_hideFilters</code></a> option to <code>false</code>.</li> |
| 312 |
<li>This widget uses jQuery's <code>.nextUntil()</code> function which is only available is jQuery version 1.4+.</li> |
| 313 |
<li>This widget <em>does NOT</em> work with tablesorter v2.0.5.</li> |
| 314 |
<li>Using the built-in filters (<a href="example-widget-filter-custom-search.html">learn how to customize them here</a> - demo created <span class="version">v2.17.5</span>): |
| 315 |
<table class="tablesorter-blue notes"> |
| 316 |
<thead> |
| 317 |
<tr> |
| 318 |
<th style="width:1%">Priority</th> |
| 319 |
<th style="width:9%">Type <small class="bright">(1)</small></th> |
| 320 |
<th style="width:30%">Description</th> |
| 321 |
<th style="width:60%">Examples</th> |
| 322 |
</tr> |
| 323 |
</thead> |
| 324 |
<tbody> |
| 325 |
<tr><td class="center">1</td><td class="center"><code>|</code> or <code> OR </code></td><td>Logical "or" (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 "box" or "bat");<button type="button" data-filter-column="1">Alex|Peter</button> (Find text that contains either "Alex" or "Peter"); <button type="button" data-filter-column="3"><20 or >40</button></td></tr> |
| 326 |
<tr><td class="center">2</td><td class="center"><code> && </code> or <code> AND </code></td><td>Logical "and". 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 "box" and "bat"), <button type="button" data-filter-column="1">Br && c</button> (Find text that contains both "br" and "c"), <button type="button" data-filter-column="3">>20 && <40</button> or <button type="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> |
| 327 |
<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 "bag", "beg", "BIG", "Bug", etc);<button type="button" data-filter-column="1">/r$/</button> (matches text that ends with an "r")</td></tr> |
| 328 |
<tr><td class="center">4</td><td class="center"><code>< <= >= ></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 type="button" data-filter-column="5">>= 10</button> (find values greater than or equal to 10)</td></tr> |
| 329 |
<tr><td class="center">5</td><td class="center"><code>!</code> or <code>!=</code></td><td>Not operator, or not exactly match. Filter the column with content that <strong>do not</strong> match the query. Include an equal (<code>=</code>), single (<code>'</code>) or double quote (<code>"</code>) to exactly <em>not</em> match a filter (<span class="version">v2.17.1</span>).</td><td><code>!fe</code> (hide rows with "female" in that column, but shows rows with "male");<button type="button" data-filter-column="1">!a</button> (find text that doesn't contain an "a");<button type="button" data-filter-column="1">!"Bruce"</button> (find content that does not exactly match "Bruce")</td></tr> |
| 330 |
<tr><td class="center">6</td><td class="center"><code>"</code> or <code>=</code></td><td>To exactly match the search query, add a quote, apostrophe or equal sign to the beginning and/or end of the query</td><td><code>abc"</code> or <code>abc=</code> (exactly match "abc");<button type="button" data-filter-column="1">John"</button> or <button type="button" data-filter-column="1">John=</button> (exactly match "John")</td></tr> |
| 331 |
<tr><td class="center">7</td><td class="center"><code> - </code> or <code> to </code></td><td>Find a range of values. Make sure there is a space before and after the dash (or the word "to") <small class="bright">(3)</small>.</td><td><button type="button" data-filter-column="3">10 - 30</button> or <button type="button" data-filter-column="4">10 to 30</button> (match values between 10 and 30)</td></tr> |
| 332 |
<tr><td class="center">8</td><td class="center"><code>?</code></td><td>Wildcard for a single, non-space character.</td><td><code>J?n</code> (finds "Jan" and "Jun", but not "Joan");<button type="button" data-filter-column="2">a?s</button> (finds "Dumass" and "Evans", but not "McMasters")</td></tr> |
| 333 |
<tr><td class="center">8</td><td class="center"><code>*</code></td><td>Wildcard for zero or more non-space characters.</td><td><code>B*k</code> (matches "Black" and "Book");<button type="button" data-filter-column="2">a*s</button> (matches "Dumass", "Evans" and "McMasters")</td></tr> |
| 334 |
<tr><td class="center">9</td><td class="center"><code>~</code></td><td>Perform a fuzzy search (matches sequential characters) by adding a tilde to the beginning of the query (<span class="version">v2.13.3</span>)</td><td><button type="button" data-filter-column="1">~bee</button> (matches "Bruce Lee" and "Brenda Dexter"), or <button type="button" data-filter-column="1">~piano</button> (matches "Philip Aaron Wong")</td></tr> |
| 335 |
<tr><td class="center">10</td><td class="center">text</td><td>Any text entered in the filter will <strong>match</strong> text found within the column</td><td><code>abc</code> (finds "abc", "abcd", "abcde", etc);<button type="button" data-filter-column="1">Aaron</button> (finds "Aaron" and "Philip Aaron Wong")</td></tr> |
| 336 |
</tbody> |
| 337 |
</table> |
| 338 |
<span class="bright">(1)</span> The filter order (or precendence) of how searches are checked in "priority" (first column) order; so an exact match will override "range" searches (*NOTE* order changed in <span class="version updated">v2.15</span>, operators prioritized before exact; see <a href="https://github.com/Mottie/tablesorter/issues/465">issue #465</a>; order changed again in <span class="version updated">v2.17.1</span> to move "not match" before "exact" and allow for exact not matches; see <a href="https://github.com/Mottie/tablesorter/issues/628">issue #628</a>). In <span class="version updated">v2.22.2</span>, the "or" and "and" types can combine any of the other filter types together.<br> |
| 339 |
<span class="bright">(2)</span> Logical "or" comparisons can now show exact matches (by default; <span class="version">v2.10.1</span>) or just match cell contents.<br> |
| 340 |
<span class="bright">(3)</span> In tablesorter <span class="version">v2.10</span>, comparisons can be made in date columns (if properly parsed). |
| 341 |
</li> |
| 342 |
</ul> |
| 343 |
</div> |
| 344 |
|
| 345 |
<h3><a href="#">Options</a></h3> |
| 346 |
<div> |
| 347 |
<h4>Filter widget defaults (added inside of tablesorter <code>widgetOptions</code>)</h4> |
| 348 |
<h4><span class="label warning">NOTE</span> This table includes very basic information about the filter options. For more extensive information & links to demos, see the main page <a href="index.html#Widget-options">Widget & Pager Options</a> section.</h4> |
| 349 |
<div> |
| 350 |
<span class="label label-info">TIP!</span> Click on the link in the function column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location. |
| 351 |
</div> |
| 352 |
<table class="options tablesorter-blue" data-sortlist="[[0,0]]"> |
| 353 |
<thead> |
| 354 |
<tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr> |
| 355 |
</thead> |
| 356 |
<tbody> |
| 357 |
|
| 358 |
<tr id="filter-child-rows"> |
| 359 |
<td><span class="permalink">filter_childRows</span></td> |
| 360 |
<td>false</td> |
| 361 |
<td>if <code>true</code>, filter includes child row content in the search.</td> |
| 362 |
</tr> |
| 363 |
|
| 364 |
<tr id="filter-child-by-column"> |
| 365 |
<td><a href="#" class="permalink">filter_childByColumn</a></td> |
| 366 |
<td>false</td> |
| 367 |
<td>if <code>true</code>, queries will search child row content by column (<span class="version">v2.22.0</span>). |
| 368 |
<div class="collapsible"> |
| 369 |
<br> |
| 370 |
The <code>filter_childRows</code> option must be <code>true</code> for this option to work.<br> |
| 371 |
<br> |
| 372 |
If <code>false</code>, and the <code>filter_childRows</code> option is <code>true</code>, then queries in <em>any column</em> will search all child content, as before this option was added. |
| 373 |
</div> |
| 374 |
</td> |
| 375 |
</tr> |
| 376 |
|
| 377 |
<tr id="filter-child-with-sibs"> |
| 378 |
<td><a href="#" class="permalink">filter_childWithSibs</a></td> |
| 379 |
<td>true</td> |
| 380 |
<td>if <code>true</code>, all sibling rows of the matching child row will also be visible (<span class="version">v2.23.4</span>). |
| 381 |
<div class="collapsible"> |
| 382 |
<p>Both <code>filter_childRows</code> & <code>filter_childByColumn</code> options must be set to <code>true</code> for this option to work.</p> |
| 383 |
If <code>false</code>, this option will only show the child row that matches the filter; and its parent row. |
| 384 |
</div> |
| 385 |
</td> |
| 386 |
</tr> |
| 387 |
|
| 388 |
<tr id="filter-column-filters"> |
| 389 |
<td><span class="permalink">filter_columnFilters</span></td> |
| 390 |
<td>true</td> |
| 391 |
<td>if <code>true</code>, a filter will be added to the top of each table column.</td> |
| 392 |
</tr> |
| 393 |
|
| 394 |
<tr id="filter-column-anymatch"> |
| 395 |
<td><a href="#" class="permalink">filter_columnAnyMatch</a></td> |
| 396 |
<td>true</td> |
| 397 |
<td>if <code>true</code>, allows using "#:{query}" in anyMatch searches (<span class="version">v2.20.0</span>). |
| 398 |
<div class="collapsible"> |
| 399 |
<br> |
| 400 |
Users can use the anymatch input to target a specific column, using a one-based index. |
| 401 |
<p></p> |
| 402 |
For example: In the table below, searching for <code>2:aa</code> in an anymatch filter will result in "Phillip Aaron Wong" and "Aaron" showing in the First Name column. |
| 403 |
<p></p> |
| 404 |
See live examples in the <a href="example-widget-filter-any-match.html#anymatch_searches">Filter Widget External Search</a> demo. |
| 405 |
</div> |
| 406 |
</td> |
| 407 |
</tr> |
| 408 |
|
| 409 |
<tr id="filter-cell-filter"> |
| 410 |
<td><a href="#" class="permalink">filter_cellFilter</a></td> |
| 411 |
<td>''</td> |
| 412 |
<td>Extra css class name (string or array) added to the filter element (input or select) (<span class="version">v2.18.0</span>) |
| 413 |
<div class="collapsible"> |
| 414 |
<br> |
| 415 |
The filter cell (<code><td></code>) is not to be confused with the <code>filter_cssFilter</code> option which adds an extra class name to the filter inputs (<code><input></code>). |
| 416 |
</div> |
| 417 |
</td> |
| 418 |
</tr> |
| 419 |
|
| 420 |
<tr id="filter-css-filter"> |
| 421 |
<td><a href="#" class="permalink">filter_cssFilter</a></td> |
| 422 |
<td>''</td> |
| 423 |
<td> |
| 424 |
Extra css class name(s) applied to the table row containing the filters & the inputs within that row (<span class="version updated">v2.15</span>). |
| 425 |
<div class="collapsible"> |
| 426 |
<br> |
| 427 |
This option can either be a string (class applied to all filters) or an array (class applied to indexed filter). |
| 428 |
</div> |
| 429 |
</td> |
| 430 |
</tr> |
| 431 |
|
| 432 |
<tr id="filter-default-attrib"> |
| 433 |
<td><span class="permalink">filter_defaultAttrib</span></td> |
| 434 |
<td>'data-value'</td> |
| 435 |
<td>this option contains the name of the data-attribute which contains the default (starting) filter value.</td> |
| 436 |
</tr> |
| 437 |
|
| 438 |
<tr id="filter-defaultfilter"> |
| 439 |
<td><span class="permalink">filter_defaultFilter</span></td> |
| 440 |
<td>{ }</td> |
| 441 |
<td>Set a default filter for a set column (<span class="version">v2.17.8</span>).</td> |
| 442 |
</tr> |
| 443 |
|
| 444 |
<tr id="filter-excludefilter"> |
| 445 |
<td><span class="permalink">filter_excludeFilter</span></td> |
| 446 |
<td>{ }</td> |
| 447 |
<td>Set a column to exclude the chosen filter types (range, exact, notMatch, etc) (<span class="version">v2.17.8</span>).</td> |
| 448 |
</tr> |
| 449 |
|
| 450 |
<tr id="filter-external"> |
| 451 |
<td><a href="#" class="permalink">filter_external</a></td> |
| 452 |
<td>''</td> |
| 453 |
<td> |
| 454 |
Set to a jQuery selector (or object) pointing to an input to be used to match the contents of any column (<span class="version">v2.15</span>). |
| 455 |
<div class="collapsible"> |
| 456 |
<br> |
| 457 |
Please refer to the updated <a href="example-widget-filter-any-match.html">filter-any-match demo</a> for the limitations of this setting. |
| 458 |
</div> |
| 459 |
</td> |
| 460 |
</tr> |
| 461 |
|
| 462 |
<tr id="filter-filtered-row"> |
| 463 |
<td><a href="#" class="permalink">filter_filteredRow</a></td> |
| 464 |
<td>'filtered'</td> |
| 465 |
<td> |
| 466 |
CSS class name added to filtered rows (rows that are not showing); needed by pager plugin. |
| 467 |
<div class="collapsible"> |
| 468 |
<br> |
| 469 |
If modifying this definition, make sure that the new class is set to <code>display: none;</code> to hide the filtered rows. |
| 470 |
</div> |
| 471 |
</td> |
| 472 |
</tr> |
| 473 |
|
| 474 |
<tr id="filter-filter-label"> |
| 475 |
<td><a href="#" class="permalink">filter_filterLabel</a></td> |
| 476 |
<td>'Filter "{{label}}" column by...'</td> |
| 477 |
<td> |
| 478 |
This option contains the ARIA-label value to be added to the filter input or select (<span class="version">v2.29.4</span>). |
| 479 |
<div class="collapsible"> |
| 480 |
<p> |
| 481 |
By default, a <code>{{label}}</code> is included in the setting to insert a column label. The content is obtained from the header cell's <code>data-label</code> attribute (do not include the <code>data-</code> prefix), if it exists, or the column header text. See the "First Name" column below for an example. |
| 482 |
</p> |
| 483 |
<span class="label label-info">Note</span> See the <a href="index.html#widget-filter-filterlabel">main page documentation for more important details</a>! |
| 484 |
</div> |
| 485 |
</td> |
| 486 |
</tr> |
| 487 |
|
| 488 |
<tr id="filter-formatter"> |
| 489 |
<td><a href="#" class="permalink">filter_formatter</a></td> |
| 490 |
<td>null</td> |
| 491 |
<td> |
| 492 |
Add custom filter element(s) to the filter row |
| 493 |
<div class="collapsible"> |
| 494 |
<br> |
| 495 |
Custom filter elements include: |
| 496 |
<ul> |
| 497 |
<li><a href="example-widget-filter-formatter-1.html">jQuery UI widgets</a>: slider, spinner & datepicker</li> |
| 498 |
<li><a href="example-widget-filter-formatter-2.html">HTML5 elements</a>: range, number input, color selector.</li> |
| 499 |
<li><a href="example-widget-filter-formatter-select2.html">Select2 plugin</a>.</li> |
| 500 |
</ul> |
| 501 |
</div> |
| 502 |
</td> |
| 503 |
</tr> |
| 504 |
|
| 505 |
<tr id="filter-functions"> |
| 506 |
<td><a href="#" class="permalink">filter_functions</a></td> |
| 507 |
<td>null</td> |
| 508 |
<td> |
| 509 |
Add custom filter functions using this option. |
| 510 |
<div class="collapsible"> |
| 511 |
<br> |
| 512 |
See the <a href="example-widget-filter-custom.html">custom filter widget functions demo</a> for more details and numerous examples. |
| 513 |
</div> |
| 514 |
</td> |
| 515 |
</tr> |
| 516 |
|
| 517 |
<tr id="filter-hide-empty"> |
| 518 |
<td><span class="permalink">filter_hideEmpty</span></td> |
| 519 |
<td>true</td> |
| 520 |
<td>Hide filter row when the table is empty (<span class="version">v2.15</span>).</td> |
| 521 |
</tr> |
| 522 |
|
| 523 |
<tr id="filter-hide-filters"> |
| 524 |
<td><span class="permalink">filter_hideFilters</span></td> |
| 525 |
<td>false</td> |
| 526 |
<td>If <code>true</code>, filters are hidden initially, but can be revealed by hovering over the filter row, or giving a filter input focus (tabbing down the page).<br> |
| 527 |
In <span class="version updated">v2.26.6</span>, a function can now be used to return a boolean value to set the visibility of the filter row. See the <a href="./#widget-filter-hidefilters">main documentation</a> for an example. |
| 528 |
</td> |
| 529 |
</tr> |
| 530 |
|
| 531 |
<tr id="filter-ignore-case"> |
| 532 |
<td><span class="permalink">filter_ignoreCase</span></td> |
| 533 |
<td>true</td> |
| 534 |
<td>If <code>true</code>, all searches are case-insensitive.</td> |
| 535 |
</tr> |
| 536 |
|
| 537 |
<tr id="filter-live-search"> |
| 538 |
<td><a href="#" class="permalink">filter_liveSearch</a></td> |
| 539 |
<td>true</td> |
| 540 |
<td> |
| 541 |
If <code>true</code>, search column content while the user types (with a short delay). |
| 542 |
<div class="collapsible"> |
| 543 |
<br> |
| 544 |
<ul> |
| 545 |
<li>If <code>false</code>, the user must press enter to start the search.</li> |
| 546 |
<li>If set to a number, when the length of the input text reaches this minimum length, a search will initiate.</li> |
| 547 |
<li>In <span class="version">v2.27.3</span>, this option can be set as an object containing column zero-based indexes or header class names. If a column isn't defined in the object, the "fallback" key is checked and if undefined, the value defaults to <code>false</code>.</li> |
| 548 |
</ul> |
| 549 |
</div> |
| 550 |
</td> |
| 551 |
</tr> |
| 552 |
|
| 553 |
<tr id="filter-matchtype"> |
| 554 |
<td><a href="#" class="permalink">filter_matchType</a></td> |
| 555 |
<td>{ 'input': 'exact', 'select': 'exact' }</td> |
| 556 |
<td> |
| 557 |
This option sets the global setting that applied to either input or select filters (<span class="version">v2.25.5</span>) |
| 558 |
<div class="collapsible"> |
| 559 |
<br> |
| 560 |
There are only two options: "exact" and "match"; and it defaults to "exact" if anything else is entered. |
| 561 |
</div> |
| 562 |
</td> |
| 563 |
</tr> |
| 564 |
|
| 565 |
<tr id="filter-only-avail"> |
| 566 |
<td><span class="permalink">filter_onlyAvail</span></td> |
| 567 |
<td>'filter-onlyAvail'</td> |
| 568 |
<td>A header with a select dropdown & this class name set, will only show available (visible) options within that drop down.</td> |
| 569 |
</tr> |
| 570 |
|
| 571 |
<tr id="filter-placeholder"> |
| 572 |
<td><span class="permalink">filter_placeholder</span></td> |
| 573 |
<td>{ search : '', select : '' }</td> |
| 574 |
<td>Default placeholder text (overridden by any header "data-placeholder" setting; <span class="version">v2.16</span>).</td> |
| 575 |
</tr> |
| 576 |
|
| 577 |
<tr id="filter-reset"> |
| 578 |
<td><span class="permalink">filter_reset</span></td> |
| 579 |
<td>null</td> |
| 580 |
<td>jQuery selector string of an element used to reset the filters (v2.4; <span class="version updated">v2.16.0</span>).</td> |
| 581 |
</tr> |
| 582 |
|
| 583 |
<tr id="filter-resetonesc"> |
| 584 |
<td><span class="permalink">filter_resetOnEsc</span></td> |
| 585 |
<td>true</td> |
| 586 |
<td>Press escape to clear filter input - normalized across browsers (<span class="version">v2.25.2</span>).</td> |
| 587 |
</tr> |
| 588 |
|
| 589 |
<tr id="filter-save-filters"> |
| 590 |
<td><span class="permalink">filter_saveFilters</span></td> |
| 591 |
<td>false</td> |
| 592 |
<td>Uses the <code>$.tablesorter.storage</code> utility to save the most recent filters.</td> |
| 593 |
</tr> |
| 594 |
|
| 595 |
<tr id="filter-search-delay"> |
| 596 |
<td><span class="permalink">filter_searchDelay</span></td> |
| 597 |
<td>300</td> |
| 598 |
<td>Typing delay in milliseconds before starting a search.</td> |
| 599 |
</tr> |
| 600 |
|
| 601 |
<tr id="filter-search-filtered"> |
| 602 |
<td><span class="permalink">filter_searchFiltered</span></td> |
| 603 |
<td>true</td> |
| 604 |
<td>Allow searching through already filtered rows in special circumstances; will speed up searching in large tables if <code>true</code>.</td> |
| 605 |
</tr> |
| 606 |
|
| 607 |
<tr id="filter-select-source"> |
| 608 |
<td><span class="permalink">filter_selectSource</span></td> |
| 609 |
<td>null</td> |
| 610 |
<td>Include a function to return an array of values to be added to the column filter select (<span class="version">v2.16.0</span>).</td> |
| 611 |
</tr> |
| 612 |
|
| 613 |
<tr id="filter-select-source-separator"> |
| 614 |
<td><span class="permalink">filter_selectSourceSeparator</span></td> |
| 615 |
<td>null</td> |
| 616 |
<td><code>filter_selectSource</code> array text left of the separator is added to the option value, right into the option text.</td> |
| 617 |
</tr> |
| 618 |
|
| 619 |
<tr id="filter-serverside-filtering"> |
| 620 |
<td><span class="permalink">filter_serversideFiltering</span></td> |
| 621 |
<td>false</td> |
| 622 |
<td>If <code>true</code>, filter will be done server-side. The client-side filtering will be disabled, but the ui and events will still be used.</td> |
| 623 |
</tr> |
| 624 |
|
| 625 |
<tr id="filter-starts-with"> |
| 626 |
<td><span class="permalink">filter_startsWith</span></td> |
| 627 |
<td>false</td> |
| 628 |
<td>If <code>true</code>, filter start from the beginning of the cell contents.</td> |
| 629 |
</tr> |
| 630 |
|
| 631 |
<tr id="filter-use-parsed-data"> |
| 632 |
<td><span class="permalink">filter_useParsedData</span></td> |
| 633 |
<td>false</td> |
| 634 |
<td>Filter all data using parsed content.</td> |
| 635 |
</tr> |
| 636 |
|
| 637 |
</tbody> |
| 638 |
<tbody> |
| 639 |
<tr><th colspan="3">Removed options</th></tr> |
| 640 |
</tbody> |
| 641 |
<tbody> |
| 642 |
|
| 643 |
<tr id="filter-any-match"> |
| 644 |
<td><span class="permalink alert">filter_anyMatch</span></td> |
| 645 |
<td>null</td> |
| 646 |
<td>jQuery selector string (or jQuery object) of external anyMatch filter (<span class="label alert">removed</span> in v2.15; please see <a href="example-widget-filter-any-match.html">the demo</a> for more details)</td> |
| 647 |
</tr> |
| 648 |
|
| 649 |
</tbody> |
| 650 |
</table> |
| 651 |
</div> |
| 652 |
|
| 653 |
<h3><a href="#">Classes</a></h3> |
| 654 |
<div> |
| 655 |
Class names that can be added to the <code>th</code> header cells: |
| 656 |
<ul> |
| 657 |
<li><code>filter-exact</code> - applies to the column where the user can use the logical "or" or "and" search. This does the opposite of the "filter-match" class, and overrides it if applied.</li> |
| 658 |
<li><code>filter-false</code> - disable the filter for a specific header column.</li> |
| 659 |
<li><code>filter-select</code> - build a default select box for a column (shows unique column content). See the <a href="example-widget-filter-custom.html">custom filter widget</a> demo for an example.</li> |
| 660 |
<li><code>filter-select-nosort</code> - when a default select box is built, this option prevents the sorting of select options leaving them in their original table order (<span class="version">v2.16.3</span>).</li> |
| 661 |
<li><code>filter-select-sort-desc</code> - when a default select box is built, it is automatically set to an ascending sort. Adding this class name will perform a descending sort on the values (<span class="version">v2.27.7</span>).</li> |
| 662 |
<li><code>filter-match</code> - applies to "filter-select" columns and columns where the user can use the logical "or" search. Makes the filter/select match the column contents instead of exactly matching.</li> |
| 663 |
<li><code>filter-parsed</code> - set a column to filter through parsed data instead of the actual table cell content.</li> |
| 664 |
<li><code>filter-onlyAvail</code> |
| 665 |
<ul> |
| 666 |
<li>Show only available (visible) options within a default select box.</li> |
| 667 |
<li>This class name is set by the <code>filter_onlyAvail</code> option.</li> |
| 668 |
<li>See the <a href="example-widget-filter-custom.html">custom filter widget</a> demo "Discount" column for an example.</li> |
| 669 |
</ul> |
| 670 |
</li> |
| 671 |
</ul> |
| 672 |
</div> |
| 673 |
|
| 674 |
<h3><a href="#">Methods</a></h3> |
| 675 |
<div> |
| 676 |
<h3 id="method-placeholder">Set Filter Placeholder Text</h3> |
| 677 |
<blockquote> |
| 678 |
Set a <code>data-placeholder</code> attribute on the associated table header with your desired placeholder text |
| 679 |
<pre class="prettyprint lang-html"><th data-placeholder="Enter Something">Name</th></pre> |
| 680 |
or, set the header cell's jQuery data |
| 681 |
<pre class="prettyprint lang-javascript">$('.tablesorter th:eq(0)').data('placeholder', 'Search for...')</pre> |
| 682 |
</blockquote> |
| 683 |
|
| 684 |
<h3 id="method-initial-search">Set Filter Initial Searches</h3> |
| 685 |
<blockquote> |
| 686 |
Set a <code>data-value</code> attribute (data-attribute name set by the <code>filter_defaultAttrib</code> option) on the associated table header with the desired initial search value. |
| 687 |
<pre class="prettyprint lang-html"><th data-value="<=100">Price</th></pre> |
| 688 |
or, set the header cell's jQuery data |
| 689 |
<pre class="prettyprint lang-javascript">$('.tablesorter th:eq(0)').data('value', '<=100')</pre> |
| 690 |
</blockquote> |
| 691 |
|
| 692 |
<h3 id="method-reset">filterReset</h3> |
| 693 |
<blockquote> |
| 694 |
Use the <code>filterReset</code> method to reset (clear) all of the current filters as follows: |
| 695 |
<pre class="prettyprint lang-javascript">$('table').trigger('filterReset');</pre> |
| 696 |
or, just add an element to your page and point to it by setting the <code>filter_reset</code> option, to allow user interaction. |
| 697 |
<p></p> |
| 698 |
<span class="label label-info">*NOTE*</span> delegated event bindings are used so these "reset" elements can be dynamically added and removed from the document. |
| 699 |
</blockquote> |
| 700 |
|
| 701 |
<h3 id="method-reset">filterResetSaved</h3> |
| 702 |
<blockquote> |
| 703 |
Use the <code>filterResetSaved</code> method to reset (clear) the saved filters (in storage) as follows (<span class="version">v2.25.6</span>): |
| 704 |
<pre class="prettyprint lang-javascript">// equivalent to: |
| 705 |
// $.tablesorter.storage( $('#table'), 'tablesorter-filters', '' ); |
| 706 |
$('#table').trigger('filterResetSaved');</pre> |
| 707 |
</blockquote> |
| 708 |
|
| 709 |
<h3 id="method-search">Search</h3> |
| 710 |
<blockquote> |
| 711 |
With this method, you can pass an array of filter values: |
| 712 |
<pre class="prettyprint lang-javascript">// apply "2?%" filter to the fifth column (zero-based index) |
| 713 |
var columns = []; |
| 714 |
columns[5] = '2?%'; |
| 715 |
// or define the array this way var columns = [ '', '', '', '', '', '2?%' ] |
| 716 |
$('table').trigger('search', [ columns ]);</pre> |
| 717 |
or, just pass <code>false</code> to refresh the current search: |
| 718 |
<pre class="prettyprint lang-javascript">$('table').trigger('search', false);</pre> |
| 719 |
* Note: using this search method will update the contents of the filters within the filter row.<br> |
| 720 |
<br> |
| 721 |
In <span class="version updated">v2.15</span>, one additional parameter can be added to the array to perform an "any-match" of the table; <span class="label warning">Warning!</span> please note that if no external input (with a <code>data-column="all"</code> is attached using <a href="index.html#function-bindsearch"><code>bindSearch</code></a> function) is visible, the user will not know that a filter has been applied. <pre class="prettyprint lang-js">// in a table with 4 columns; set the 5th parameter to any-match |
| 722 |
$('table').trigger( 'search', [['', '', '', '', 'orange']] ); // find orange in any column</pre> |
| 723 |
</blockquote> |
| 724 |
|
| 725 |
<h3 id="method-get-filters">Get current filters</h3> |
| 726 |
<blockquote> |
| 727 |
Get an array of the currently applied filters (<span class="version">v2.9</span>). |
| 728 |
<pre class="prettyprint lang-javascript">$.tablesorter.getFilters( $('table') ); // or $('table.hasFilters')</pre> |
| 729 |
This method returns an array of filter values or <code>false</code> if the selected table does not contain a filter row.<br> |
| 730 |
<br> |
| 731 |
Internally, the get filters functions returns the filters stored within this table data <code>$('table').data('lastSearch')</code>, unless an additional parameter of <code>true</code> is passed to the function: |
| 732 |
<pre class="prettyprint lang-javascript">$.tablesorter.getFilters( $('table'), true ); // get current input values instead of data stored filters</pre> |
| 733 |
As of <span class="version updated">v2.15</span>, if an external "any-match" filter (see <code>filter_external</code> widget option) is included, one additional array parameter will be returned in the filter - the value of the any match search. |
| 734 |
<pre class="prettyprint lang-js">// in a table with six columns, this function will return an array with seven |
| 735 |
// parameters; something like this: [ '', '', '', '', '', '', '11' ], |
| 736 |
// where the "11" will be obtained from the "any-match" input |
| 737 |
var filters = $.tablesorter.getFilters( $('table') );</pre> |
| 738 |
</blockquote> |
| 739 |
|
| 740 |
<h3 id="method-set-filters">Set current filters</h3> |
| 741 |
<blockquote> |
| 742 |
Set the values of the actual filters using this method; include a <code>false</code> boolean to not apply the search (<span class="version">v2.9</span>). |
| 743 |
<p>In <span class="version update">v2.24.3</span>, if the last boolean parameter is <code>undefined</code> or set to <code>true</code>, the search <em>will be applied</em>. Only when the boolean is set to <code>false</code> will the search <em>not</em> be applied!</p> |
| 744 |
<pre class="prettyprint lang-javascript">// update filters, AND apply the search |
| 745 |
$.tablesorter.setFilters( $('table'), [ '', '', '', '', '', '2?%' ] ); // , true is optional |
| 746 |
|
| 747 |
// update filters, but DOES NOT apply the search |
| 748 |
$.tablesorter.setFilters( $('table'), [ '', '', '', '', '', '2?%' ], false );</pre> |
| 749 |
This method returns <code>true</code> if the filters were sucessfully applied, or <code>false</code> if the table does have a filter row.<br> |
| 750 |
<br> |
| 751 |
As of <span class="version updated">v2.15</span>, if an external "any-match" filter (see <code>filter_external</code> widget option) is included, add an additional array parameter to set that filter; so if a table has six columns, add the any-match search as the seventh value. |
| 752 |
<pre class="prettyprint lang-js">// in a table with 6 columns, the 7th filter will apply |
| 753 |
// to the any-match filter & match any table column with "11" |
| 754 |
$.tablesorter.setFilters( $('table'), [ '', '', '', '', '', '', '11' ], true );</pre> |
| 755 |
</blockquote> |
| 756 |
|
| 757 |
<h3 id="method-bind-filters">Bind external filter</h3> |
| 758 |
<blockquote> |
| 759 |
Use this method to bind external search filters |
| 760 |
<ul> |
| 761 |
<li>Include a data-attribute <code>data-column</code> with the column index to target</li> |
| 762 |
<li>Or, use <code>data-column="all"</code> to preform an "any-match" search on all of the table columns (<span class="version updated">v2.15</span>).</li> |
| 763 |
<li>Or, add multiple columns <code>data-column="0-2,4,6-8"</code> to perform an "any-match" search on selected columns (<span class="version">v2.18.0</span>).</li> |
| 764 |
</ul> |
| 765 |
If no <code>data-column</code> is added to the input, the input will be ignored. |
| 766 |
<pre class="prettyprint lang-html"><!-- will perform an "any-match" type of search (matches any column) --> |
| 767 |
<input type="search" class="search" data-column="all"> |
| 768 |
<!-- will only search the first column (zero-based index) --> |
| 769 |
<input type="search" class="search" data-column="0"></pre> |
| 770 |
<pre class="prettyprint lang-javascript">// Target the $('.search') input using built in functioning |
| 771 |
// this binds to the search using "search" and "keyup" and allows using filter_liveSearch |
| 772 |
// or delayed search & pressing escape to cancel the search |
| 773 |
// pass an optional third parameter (false boolean) to force the inputs to update |
| 774 |
// this allows changing the data-column for an input dynamically |
| 775 |
$.tablesorter.filter.bindSearch( $table, $('.search'), false );</pre> |
| 776 |
If you don't care about the enhanced search filter, then bind to both the "keyup" and "search" events |
| 777 |
<pre class="prettyprint lang-javascript">// Basic search binding, alternate to the above |
| 778 |
// bind to search - pressing enter and clicking on "x" to clear (Webkit) |
| 779 |
// keyup allows dynamic searching |
| 780 |
$(".search").bind('search keyup', function (e) { |
| 781 |
$('table').trigger('search', [ [this.value] ]); |
| 782 |
}); |
| 783 |
</pre></blockquote> |
| 784 |
|
| 785 |
</div> |
| 786 |
|
| 787 |
<h3><a href="#">Events</a></h3> |
| 788 |
<div> |
| 789 |
<ul> |
| 790 |
<li><code>filterEnd</code> - Event triggered when the filter widget has finished processing the search.</li> |
| 791 |
<li><code>filterInit</code> - Event triggered when the filter widget has finished initializing.</li> |
| 792 |
<li><code>filterStart</code> - Event triggered when the filter widget has started processing the search.</li> |
| 793 |
</ul> |
| 794 |
</div> |
| 795 |
|
| 796 |
<h3><a href="#">Changes</a></h3> |
| 797 |
<div class="inner"> |
| 798 |
Moved to the wiki pages - <a href="https://github.com/Mottie/tablesorter/wiki/Changes">change log</a>. |
| 799 |
</div> |
| 800 |
|
| 801 |
<h3><a href="#">Localization</a></h3> |
| 802 |
<div class="inner"> |
| 803 |
You can now change the language of the searches used within the filter widget. For example, to change the localization to French, do the following: |
| 804 |
<pre class="prettyprint lang-js">// add French support |
| 805 |
$.extend($.tablesorter.language, { |
| 806 |
to : 'à', |
| 807 |
or : 'ou', |
| 808 |
and : 'et' |
| 809 |
});</pre>If you want to support multiple languages, separate the language variables with a vertical bar (<code>|</code>, <kbd>Shift</kbd> + <kbd>\</kbd>): |
| 810 |
<pre class="prettyprint lang-js">// add French & Spanish support |
| 811 |
$.extend($.tablesorter.language, { |
| 812 |
to : 'à|a', |
| 813 |
or : 'ou|o', |
| 814 |
and : 'et|y' |
| 815 |
});</pre> |
| 816 |
<h3>Notes</h3> |
| 817 |
<ul> |
| 818 |
<li><span class="label label-info">Info</span> These changes still require the user to enter spaces in the filter to perform the search, e.g. <code>1 à 10</code> (shows rows with numbers between 1 and 10).</li> |
| 819 |
<li><span class="label label-info">Info</span> Extra spaces around the value will be trimmed and it is valid to set a value to an empty string; but this won't disable the filter type (use <code>-</code> for "to", <code>|</code> for "or" and <code>&&</code> for "and").</li> |
| 820 |
<li> |
| 821 |
<span class="label warning">Warning</span> These language values are added to a regular expression using <code>new RegExp()</code>: |
| 822 |
<ul> |
| 823 |
<li>So you will need to escape any special characters contained in these values (e.g. <code>. \ + * ? [ ^ ] $ ( ) { } = ! < > | : -</code>).</li> |
| 824 |
<li>This function might help (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters">ref</a>): |
| 825 |
<pre class="prettyprint lang-js">function escapeRegExp( string ) { |
| 826 |
return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); |
| 827 |
}</pre> |
| 828 |
</li> |
| 829 |
</ul> |
| 830 |
</li> |
| 831 |
</ul> |
| 832 |
</div> |
| 833 |
|
| 834 |
</div> |
| 835 |
<p></p> |
| 836 |
|
| 837 |
<h1>Demo</h1> |
| 838 |
<button type="button" class="toggle fsw">Toggle</button> filter_startsWith : <span id="start">false</span> (if true, search from beginning of cell content only)<br> |
| 839 |
<button type="button" class="toggle fic">Toggle</button> filter_ignoreCase : <span id="case">true</span> (if false, the search will be case sensitive)<br> |
| 840 |
<button type="button" class="toggle ffm">Toggle</button> filter-match (if class name added to the "First Name" column, all "or" searches will only match the content; Search <button type="button" data-filter-column="1">alex|br*|c</button> in the First Name column (<span class="version">2.10.1</span>). |
| 841 |
<hr> |
| 842 |
|
| 843 |
<div id="demo">Search <button type="button" data-filter-column="5" data-filter-text="2?%">2?%</button> in the Discount column<br> |
| 844 |
<button type="button" class="reset">Reset</button> |
| 845 |
<button type="button" class="resetsaved" title="Reload the page to see that the saved filters have cleared">Reset Saved Filters</button> |
| 846 |
|
| 847 |
<table id="table" class="tablesorter"> |
| 848 |
<thead> |
| 849 |
<tr> |
| 850 |
|
| 851 |
<th data-placeholder="" class="filter-false">Rank</th> |
| 852 |
<th data-placeholder="Try B*{space} or alex|br*|c" data-label="First Name" data-test="" class="filter-match">First Name (<span></span> filter-match )</th> |
| 853 |
<th data-placeholder="Try <d">Last Name</th> |
| 854 |
<th data-placeholder="Try >=33">Age</th> |
| 855 |
<th data-placeholder="Try <9.99">Total</th> |
| 856 |
<th data-placeholder="Try 2?%">Discount</th> |
| 857 |
<th data-placeholder="Try /20[^0]\d/ or >1/1/2010">Date</th> |
| 858 |
</tr> |
| 859 |
</thead> |
| 860 |
<tbody> |
| 861 |
<tr><td>1</td><td>Philip Aaron Wong</td><td>Johnson Sr Esq</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2004 7:22 AM</td></tr> |
| 862 |
<tr><td>11</td><td>Aaron</td><td>Hibert</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2009 12:21 PM</td></tr> |
| 863 |
<tr><td>12</td><td>Brandon Clark</td><td>Henry Jr</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2000 1:15 PM</td></tr> |
| 864 |
<tr><td>111</td><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr> |
| 865 |
<tr><td>21</td><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr> |
| 866 |
<tr><td>013</td><td>Clark</td><td>Kent Sr.</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr> |
| 867 |
<tr><td>005</td><td>Bruce</td><td>Almighty Esq</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2021 9:12 AM</td></tr> |
| 868 |
<tr><td>10</td><td>Alex</td><td>Dumass</td><td>13</td><td>$5.29</td><td>4%</td><td>Jan 8, 2012 5:11 PM</td></tr> |
| 869 |
<tr><td>16</td><td>Jim</td><td>Franco</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2004 11:23 AM</td></tr> |
| 870 |
<tr><td>166</td><td>Bruce Lee</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr> |
| 871 |
<tr><td>100</td><td>Brenda Dexter</td><td>McMasters</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2010 7:23 PM</td></tr> |
| 872 |
<tr><td>55</td><td>Dennis</td><td>Bronson</td><td>65</td><td>$123.00</td><td>32%</td><td>Jan 20, 2001 1:12 PM</td></tr> |
| 873 |
<tr><td>9</td><td>Martha</td><td>delFuego</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2011 10:55 AM</td></tr> |
| 874 |
</tbody> |
| 875 |
</table></div> |
| 876 |
|
| 877 |
<h1>Page Header</h1> |
| 878 |
<div> |
| 879 |
<pre class="prettyprint lang-html"><!-- blue theme stylesheet --> |
| 880 |
<link rel="stylesheet" href="css/theme.blue.css"> |
| 881 |
<!-- tablesorter plugin --> |
| 882 |
<script src="js/jquery-latest.min.js"></script> |
| 883 |
<script src="js/jquery.tablesorter.js"></script> |
| 884 |
|
| 885 |
<!-- tablesorter widget file - loaded after the plugin --> |
| 886 |
<script src="js/jquery.tablesorter.widgets.js"></script></pre> |
| 887 |
</div> |
| 888 |
|
| 889 |
<h1>Javascript</h1> |
| 890 |
<div id="javascript"> |
| 891 |
<pre class="prettyprint lang-javascript"></pre> |
| 892 |
</div> |
| 893 |
|
| 894 |
<h1>CSS</h1> |
| 895 |
<div> |
| 896 |
<pre class="prettyprint lang-css">/* REQUIRED in CUSTOM THEMES! |
| 897 |
This is the only definition that MUST BE added to any custom themes. |
| 898 |
This is how rows are hidden by filtering (included in provided themes) */ |
| 899 |
.tablesorter .filtered { |
| 900 |
display: none; |
| 901 |
} |
| 902 |
|
| 903 |
/* All of the following css is already contained within each theme file; modify it as desired */ |
| 904 |
/* filter row */ |
| 905 |
.tablesorter-filter-row td { |
| 906 |
background: #eee; |
| 907 |
line-height: normal; |
| 908 |
text-align: center; /* center the input */ |
| 909 |
-webkit-transition: line-height 0.1s ease; |
| 910 |
-moz-transition: line-height 0.1s ease; |
| 911 |
-o-transition: line-height 0.1s ease; |
| 912 |
transition: line-height 0.1s ease; |
| 913 |
} |
| 914 |
/* optional disabled input styling */ |
| 915 |
.tablesorter-filter-row .disabled { |
| 916 |
opacity: 0.5; |
| 917 |
filter: alpha(opacity=50); |
| 918 |
cursor: not-allowed; |
| 919 |
} |
| 920 |
|
| 921 |
/* hidden filter row */ |
| 922 |
.tablesorter-filter-row.hideme td { |
| 923 |
/*** *********************************************** ***/ |
| 924 |
/*** change this padding to modify the thickness ***/ |
| 925 |
/*** of the closed filter row (height = padding x 2) ***/ |
| 926 |
padding: 2px; |
| 927 |
/*** *********************************************** ***/ |
| 928 |
margin: 0; |
| 929 |
line-height: 0; |
| 930 |
cursor: pointer; |
| 931 |
} |
| 932 |
.tablesorter-filter-row.hideme * { |
| 933 |
height: 1px; |
| 934 |
min-height: 0; |
| 935 |
border: 0; |
| 936 |
padding: 0; |
| 937 |
margin: 0; |
| 938 |
/* don't use visibility: hidden because it disables tabbing */ |
| 939 |
opacity: 0; |
| 940 |
filter: alpha(opacity=0); |
| 941 |
} |
| 942 |
|
| 943 |
/* filters */ |
| 944 |
.tablesorter-filter { |
| 945 |
width: 95%; |
| 946 |
height: inherit; |
| 947 |
margin: 4px; |
| 948 |
padding: 4px; |
| 949 |
background-color: #fff; |
| 950 |
border: 1px solid #bbb; |
| 951 |
color: #333; |
| 952 |
-webkit-box-sizing: border-box; |
| 953 |
-moz-box-sizing: border-box; |
| 954 |
box-sizing: border-box; |
| 955 |
-webkit-transition: height 0.1s ease; |
| 956 |
-moz-transition: height 0.1s ease; |
| 957 |
-o-transition: height 0.1s ease; |
| 958 |
transition: height 0.1s ease; |
| 959 |
}</pre> |
| 960 |
</div> |
| 961 |
|
| 962 |
<h1>HTML</h1> |
| 963 |
<div id="html"> |
| 964 |
<pre class="prettyprint lang-html"></pre> |
| 965 |
</div> |
| 966 |
|
| 967 |
<div class="next-up"> |
| 968 |
<hr /> |
| 969 |
Next up: <a href="example-widget-filter-any-match.html">jQuery Any Match filter widget ››</a> |
| 970 |
</div> |
| 971 |
|
| 972 |
</div> |
| 973 |
|
| 974 |
</body> |
| 975 |
</html> |