Debian Codegraph @

docs/example-widget-filter-formatter-1.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Custom Filter Widget Formatter (jQuery UI widgets)</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <script src="js/jquery-ui.min.js"></script>
12 <link rel="stylesheet" href="css/jq.css">
13 <link href="css/prettify.css" rel="stylesheet">
14 <script src="js/prettify.js"></script>
15 <script src="js/docs.js"></script>
16
17 <!-- jQuery UI theme switcher: https://github.com/pontikis/jui_theme_switch/ -->
18 <style>
19 th { width: 15%; }
20 .reset { margin: 4px; }
21 #switcher { float: left; }
22 .switcher_container { padding: 5px; }
23 .switcher_list { padding: 2px; }
24 .switcher_label { margin-right: 5px; }
25 </style>
26 <script src="js/jquery.jui_theme_switch.min.js"></script>
27
28 <style id="css">/* css needed to get compare selector & slider in-line */
29 .compare-select-wrapper { min-width: 60%; float: right; }</style>
30
31 <!-- Tablesorter: required; also include any of the jQuery UI themes -->
32 <link id="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
33 <link href="../css/theme.jui.css" rel="stylesheet">
34 <link href="../css/filter.formatter.css" rel="stylesheet">
35 <script src="../js/jquery.tablesorter.js"></script>
36 <script src="../js/widgets/widget-filter.js"></script>
37 <script src="../js/widgets/widget-stickyHeaders.js"></script>
38 <script src="../js/widgets/widget-storage.js"></script>
39 <script src="../js/widgets/widget-uitheme.js"></script>
40 <script src="../js/widgets/widget-filter-formatter-jui.js"></script>
41 <script>
42 $(function() {
43
44 $('#switcher').jui_theme_switch({
45 stylesheet_link_id : 'ui-theme',
46 datasource_url : 'assets/theme_switcher.json'
47 });
48
49 $('.accordion button').on('click', function() {
50 var $this = $(this),
51 column = $this.data('column'),
52 filters = [];
53 filters[ column ] = $this.data('value');
54 $('table').trigger('sorton', [ [[column, 0]], function() {
55 $.tablesorter.setFilters( $('table'), filters, true );
56 } ]);
57 });
58
59 });
60 </script>
61 <script id="js">$(function() {
62
63 // call the tablesorter plugin
64 $("table").tablesorter({
65 theme : 'jui',
66 headerTemplate : '{content}{icon}',
67 // hidden filter input/selects will resize the columns, so try to minimize the change
68 widthFixed : true,
69 // initialize zebra striping and filter widgets
70 widgets : ["zebra", "filter", "stickyHeaders", "uitheme"],
71 widgetOptions : {
72 // Use the $.tablesorter.storage utility to save the most recent filters
73 filter_saveFilters : true,
74 // jQuery selector string of an element used to reset the filters
75 filter_reset : 'button.reset',
76 // add custom selector elements to the filter row
77 filter_formatter : {
78
79 // Rank (jQuery selector added v2.17.0)
80 'th:contains("Rank")' : function($cell, indx) {
81 return $.tablesorter.filterFormatter.uiSlider( $cell, indx, {
82 delayed : true,
83 valueToHeader : false,
84 cellText : 'Rank:',
85 compare : [ '=', '>=', '<=' ],
86 selected : 2, // zero-based index of compare starting selected value
87 // jQuery UI slider options
88 value : 100,
89 min : 0,
90 max : 100
91 });
92 },
93
94 // Age
95 1 : function($cell, indx) {
96 return $.tablesorter.filterFormatter.uiSlider( $cell, indx, {
97 delayed : false,
98 valueToHeader : false,
99 exactMatch : false,
100 allText : 'all', // this is ignored when compare is not empty
101 compare : [ '=', '>=', '<=' ],
102 selected : 1,
103 // jQuery UI slider options
104 value : 1,
105 min : 1,
106 max : 65
107 });
108 },
109
110 // Total (jQuery selector added v2.17.0)
111 '.total' : function($cell, indx) {
112 return $.tablesorter.filterFormatter.uiRange( $cell, indx, {
113 delayed : false,
114 valueToHeader : false,
115 // jQuery UI slider options
116 values : [1, 160],
117 min : 1,
118 max : 160
119 });
120 },
121
122 // Discount
123 3 : function($cell, indx) {
124 return $.tablesorter.filterFormatter.uiSpinner( $cell, indx, {
125 delayed : true,
126 addToggle : false,
127 exactMatch : true,
128 compare : [ '', '=', '>=', '<=' ],
129 selected : 2,
130 // jQuery UI spinner options
131 min : 0,
132 max : 45,
133 value : 1,
134 step : 1
135 });
136 },
137
138 // Date (one input)
139 4 : function($cell, indx) {
140 return $.tablesorter.filterFormatter.uiDateCompare( $cell, indx, {
141 cellText : 'Dates', // text added before the input
142 compare : [ '', '=', '>=', '<=' ],
143 selected : 3,
144 // jQuery UI datepicker options
145 // defaultDate : '1/1/2014', // default date
146 changeMonth : true,
147 changeYear : true
148
149 });
150 },
151
152 // Date (two inputs)
153 5 : function($cell, indx) {
154 return $.tablesorter.filterFormatter.uiDatepicker( $cell, indx, {
155 // from : '08/01/2013', // default from date
156 // to : '1/18/2014', // default to date
157 changeMonth : true,
158 changeYear : true
159 });
160 }
161 },
162
163 // added v2.16
164 filter_placeholder : {
165 from : 'From...',
166 to : 'To...'
167 }
168 }
169 });
170
171 });</script>
172
173 </head>
174 <body>
175 <div id="banner">
176 <h1>table<em>sorter</em></h1>
177 <h2>Custom Filter Widget Formatter (jQuery UI widgets)</h2>
178 <h3>Flexible client-side table sorting</h3>
179 <a href="index.html">Back to documentation</a>
180 </div>
181 <div id="main">
182
183 <p></p>
184 <br>
185 <div class="accordion">
186
187 <h3><a href="#">Notes</a></h3>
188 <div>
189 <ul>
190 <li>Oct 27, 2014 - added <a href="http://jsfiddle.net/Mottie/abkNM/4406/">a demo</a> to the <a href="https://github.com/Mottie/tablesorter/wiki">home wiki page</a> showing how to apply <a href="http://jqueryui.com/selectmenu/">jQuery's selectmenu widget</a> to a filter cell without using the filter formatter functions.</li>
191 <li>As of <span class="version">v2.17.5</span>, if writing a custom filterFormatter function, you'll need to call an additional function after initialization has completed so the "filterInit" event isn't triggered prematurely. See the "Custom Filter Formatter Function Information" section below for more details.</li>
192 <li>In <span class="version updated">v2.17.0</span>, the <code>filter_formatter</code> column can also be referenced by using a jQuery selector (e.g. class name or ID).</li>
193 <li>In <span class="version">v2.16.0</span>, the <code>filter_placeholder</code> option was added. See the jQuery UI Datepicker Range Selector section for more details.</li>
194 <li>In <span class="version">v2.15.0</span>, the following changes were made:
195 <ul>
196 <li>These updated filter widget functions are not completely backward compatible with older versions of the filter widget. Please update both!</li>
197 <li>Added <code>compare</code> &amp; <code>selected</code> options:
198 <ul>
199 <li>These options allow the adding of a comparison operator selector to the cell (e.g. <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>, etc).</li>
200 <li>If any <code>cellText</code> is included, it is now wrapped in a label with a class name of "compare-select-label" and "compare-select-label#" (where "#" is the column index).</li>
201 <li>The selector has a class name of "compare-select" and "compare-select#" (where "#" is the column index)</li>
202 <li>Whichever type of input that is added to the cell is then wrapped in a div with class "compare-select-wrapper" and "compare-select-wrapper#" (where "#" is the column index).</li>
203 <li>These class names allow styling of an individual filter to keep elements in line, or however you wish to style it.
204 <pre class="prettyprint lang-html">&lt;!-- rendered filter cell (first column) --&gt;
205 &lt;td&gt;
206 &lt;!-- cellText --&gt;
207 &lt;label class=&quot;compare-select-label compare-select-label0&quot;&gt;Rank:&lt;/label&gt;
208 &lt;!-- compare: [ '=', '&gt;=', '&lt;=' ] --&gt;
209 &lt;select class=&quot;compare-select compare-select0&quot;&gt;
210 &lt;option&gt;=&lt;/option&gt;
211 &lt;option&gt;&amp;gt;=&lt;/option&gt;
212 &lt;option selected&gt;&amp;lt;=&lt;/option&gt;
213 &lt;/select&gt;
214 &lt;!-- wrapped selector element --&gt;
215 &lt;div class=&quot;compare-select-wrapper compare-select-wrapper0&quot;&gt;
216 &lt;div class=&quot;slider slider0&gt;&lt;!-- jQuery UI Slider gets added here --&gt;&lt;/div&gt;
217 &lt;/div&gt;
218 &lt;!-- hidden input --&gt;
219 &lt;input class=&quot;filter tablesorter-filter&quot; type=&quot;hidden&quot; value=&quot;&quot; data-column=&quot;0&quot;&gt;
220 &lt;/td&gt;</pre>
221 </li>
222 </ul>
223 </li>
224 <li>Filter reset now sets these filters to their default values, not an empty string.</li>
225 <li>Updated to now properly restore saved filters.</li>
226 <li>Added <code>endOfDay</code> option for jQuery UI Datepicker.
227 <ul>
228 <li>When <code>true</code> search dates will include all times from the date chosen when a comparison is made of dates "less than" the set date.</li>
229 <li>Example 1: if a table entry has a date of "Jan 14, 2014 11:23 AM" and the filter search is set to <button type="button" data-column="4" data-value="<=1/14/2014">&lt;= 1/14/2014</button>, the table entry will be included in the search; the default set time would otherwise be "1/14/2014 00:00:00" and not include the entry from "11:23 AM". So, the <code>endOfDay</code> option sets the time to "23:59:59".</li>
230 <li>Example 2: if searching for one specific date, this option will now search for all times within that day. For example, searching for <button type="button" data-column="4" data-value="=1/20/2014">= 1/20/2014</button>, and the results will include dates from 1/20/2014 00:00:00 to 1/20/2014 23:59:59.</li>
231 <li>When comparing dates greater than the set date, the time will be set to midnight; so this option will not be applied.</li>
232 <li>Example 3: in two date inputs, the <code>endOfDay</code> time is only applied to the "to" input; search for <button type="button" data-column="5" data-value="1/20/2014 - 1/20/2014">1/20/2014 - 1/20/2014</button></li>
233 <li>This option is available in both the comparison (one input) and range (two inputs; "to" date input only) date pickers.</li>
234 </ul>
235 </li>
236 </ul>
237 </li>
238 <li>As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.</li>
239 <li>This page shows you how to add a few <strong>jQuery UI widgets</strong> to interact with the filter widget using the <code>filter_formatter</code> option.</li>
240 <li>Custom filter widget option <code>filter_formatter</code> was added in version 2.7.7.</li>
241 <li>jQuery v1.4.3+ required.</li>
242 </ul>
243 </div>
244
245 <h3><a href="#"><strong>jQuery UI Single Slider</strong></a> <span class="xsmall">("Rank" and "Age" columns)</span></h3>
246 <div>
247 <ul>
248 <li>In <span class="version">v2.15.0</span> the <code>compare</code> option was updated to allow adding a selector along with the input. The <code>selected</code> option allows choosing the default setting.</li>
249 <li>In <span class="version">v2.10.1</span> the <code>compare</code> option was added. This allows comparing the slider's value to the column value. The slider in the Age column is selecting values greater than or equal to itself.</li>
250 <li>A search delay was added in v2.7.11 (time set by <code>filter_searchDelay</code> option). It can be disabled by setting the <code>delayed</code> option to <code>false</code>.<br><br></li>
251 <li>This example shows how you can add a jQuery UI slider to filter column content.</li>
252 <li>The <code>filter_formatter</code> function provided in the extra "widget-filter-formatter-jui.js" file is used to add this custom control within the filter row.</li>
253 <li>Make sure to include all values within the selected range, otherwise rows outside of this range will be forever hidden.</li>
254 <li>Add the following code to apply a slider to filter a column:<pre class="prettyprint lang-javascript">$(function() {
255
256 $("table").tablesorter({
257 theme: 'jui',
258 // hidden filter input/selects will resize the columns, so try to minimize the change
259 widthFixed : true,
260 // initialize zebra striping and filter widgets
261 widgets: ["zebra", "filter", "uitheme"],
262 widgetOptions : {
263 // jQuery selector string of an element used to reset the filters
264 filter_reset : 'button.reset',
265 // add custom selector elements to the filter row
266 filter_formatter : {
267
268 // Rank (jQuery selector added v2.17.0)
269 'th:contains("Rank")' : function($cell, indx) {
270 return $.tablesorter.filterFormatter.uiSlider( $cell, indx, {
271 // filterFormatter options
272 cellText : 'Rank:',
273 delayed: true, // delay search (set by filter_searchDelay)
274 valueToHeader: false, // add current slider value to the header cell
275 exactMatch: true, // exact (true) or match (false)
276 allText: 'all', // text shown when the slider is at the minimum value
277 compare : [ '=', '&gt;=', '&lt;=' ], // any comparison would override the exactMatch option
278 selected : 2, // zero-based index of compare starting selected value
279
280 // add any of the jQuery UI Slider options here (http://api.jqueryui.com/slider/)
281 value: 100, // starting value
282 min: 0, // minimum value
283 max: 100 // maximum value
284 });
285 },
286
287 // Age
288 1 : function($cell, indx) {
289 return $.tablesorter.filterFormatter.uiSlider( $cell, indx, {
290 delayed: false, // delay search (set by filter_searchDelay)
291 valueToHeader: false, // add current slider value to the header cell
292 exactMatch: false, // exact (true) or match (false)
293 allText: 'all', // text shown when slider is at the minimum value; ignored when compare has a value
294 compare: [ '=', '&gt;=', '&lt;=' ], // search values greater/less than selected value; overrides exactMatch
295 selected : 1, // zero-based index of compare starting selected value
296
297 // add any of the jQuery UI Slider options here (http://api.jqueryui.com/slider/)
298 value: 1, // starting value
299 min: 1, // minimum value
300 max: 65 // maximum value
301 });
302 }
303
304 }
305 }
306 });
307
308 });</pre></li>
309 <li>The tooltip above the slider is added using pure css, which is included in the "filter.formatter.css" file, but it won't work in IE7 and older. But, you set the <code>valueToHeader</code> option to <code>true</code> to add the slider value to the header cell above the filter.</li>
310 <li>Another option named <code>exactMatch</code> was added to allow exact or general matching of column content.</li>
311 <li>Notice that the left-most value, zero in this case, will clear the column filter to allow a method to show all column content. You can modify the "all" text using the <code>allText</code> option.</li>
312 </ul>
313 </div>
314
315 <h3><a href="#"><strong>jQuery UI Range Slider</strong></a> <span class="xsmall">("Total" column)</span></h3>
316 <div>
317 <ul>
318 <li>This example shows how you can add a jQuery UI range slider to filter column content.</li>
319 <li>The <code>filter_formatter</code> function provided in the extra "widget-filter-formatter-jui.js" file is used to add this custom control within the filter row.</li>
320 <li>Make sure to include all values within the selected range, otherwise rows outside of this range will be forever hidden.</li>
321 <li>The range slider is actually the same as the single slider described above, but was built to handle a range of values.</li>
322 <li>Add the following code to apply a range slider to filter a column:<pre class="prettyprint lang-javascript">$(function() {
323
324 $("table").tablesorter({
325 theme: 'jui',
326 // hidden filter input/selects will resize the columns, so try to minimize the change
327 widthFixed : true,
328 // initialize zebra striping and filter widgets
329 widgets: ["zebra", "filter", "uitheme"],
330 widgetOptions : {
331 // jQuery selector string of an element used to reset the filters
332 filter_reset : 'button.reset',
333 // add custom selector elements to the filter row
334 filter_formatter : {
335
336 // Total column (jQuery selector added v2.17.0)
337 '.total' : function($cell, indx) {
338 return $.tablesorter.filterFormatter.uiRange( $cell, indx, {
339 delayed: true, // delay search (set by filter_searchDelay)
340 valueToHeader: false, // add current slider value to the header cell
341
342 // add any of the jQuery UI Slider options (for range selection) here (http://api.jqueryui.com/slider/)
343 values: [1, 160], // starting range
344 min: 1, // minimum value
345 max: 160 // maximum value
346 });
347 }
348
349 }
350 }
351 });
352
353 });</pre></li>
354 <li>The tooltip above the slider is added using pure css, which is included in the "filter.formatter.css" file, but it won't work in IE7 and older. But, you set the <code>valueToHeader</code> option to <code>true</code> to add the slider value to the header cell above the filter.</li>
355 <li>Another option named <code>exactMatch</code> was added to allow exact or general matching of column content.</li>
356 <li>A search delay was added in v2.7.11 (time set by <code>filter_searchDelay</code> option). It can be disabled by setting the <code>delayed</code> option to <code>false</code>.</li>
357 </ul>
358 </div>
359
360 <h3><a href="#"><strong>jQuery UI Spinner</strong></a> <span class="xsmall">("Discount" column)</span></h3>
361 <div>
362 <ul>
363 <li>In <span class="version">v2.15.0</span> the <code>compare</code> option was updated to allow adding a selector along with the input. The <code>selected</code> option allows choosing the default setting.<br><br></li>
364 <li>This example shows how you can add a jQuery UI spinner to filter column content.</li>
365 <li>The <code>filter_formatter</code> function provided in the extra "widget-filter-formatter-jui.js" file is used to add this custom control within the filter row.</li>
366 <li>Add the following code to apply a spinner to filter a column:<pre class="prettyprint lang-javascript">$(function() {
367
368 $("table").tablesorter({
369 theme: 'jui',
370 // hidden filter input/selects will resize the columns, so try to minimize the change
371 widthFixed : true,
372 // initialize zebra striping and filter widgets
373 widgets: ["zebra", "filter", "uitheme"],
374 widgetOptions : {
375 // jQuery selector string of an element used to reset the filters
376 filter_reset : 'button.reset',
377 // add custom selector elements to the filter row
378 filter_formatter : {
379
380 // Discount column
381 3 : function($cell, indx) {
382 return $.tablesorter.filterFormatter.uiSpinner( $cell, indx, {
383 delayed: true, // delay search (set by filter_searchDelay)
384 addToggle: false, // add a toggle switch to activate/deactive the search
385 exactMatch: true, // exact (true) or match (false)
386 compare : [ '', '=', '&gt;=', '&lt;=' ], // search values greater/less than selected value; overrides exactMatch
387 selected : 2, // zero-based index of compare starting selected value
388
389 // add any of the jQuery UI Spinner options here (http://api.jqueryui.com/spinner/)
390 min : 0,
391 max : 45,
392 value: 1,
393 step: 1
394 });
395 }
396 }
397 }
398 });
399
400 });</pre></li>
401 <li>This is the only jQuery UI widget that includes a toggle button. The toggle button is added by default, but if you don't want it, set the <code>addToggle</code> option to <code>false</code>. Without the toggle button, the filter is always active.</li>
402 <li>Another option named <code>exactMatch</code> was added to allow exact or general matching of column content.</li>
403 <li>A search delay was added in v2.7.11 (time set by <code>filter_searchDelay</code> option). It can be disabled by setting the <code>delayed</code> option to <code>false</code>.</li>
404 </ul>
405 </div>
406
407 <h3><a href="#"><strong>jQuery UI Datepicker Comparison</strong></a> <span class="xsmall">("Date (one input)" column)</span></h3>
408 <div>
409 <ul>
410 <li>In <span class="version">v2.15.0</span>
411 <ul>
412 <li>The <code>compare</code> option was updated to allow adding a selector along with the input. The <code>selected</code> option allows choosing the default setting.</li>
413 <li>A <code>endOfDay</code> option was added, which when a <code>&lt;=</code> comparison is made, will include all times within the selected day. Try searching for <button type="button" data-column="4" data-value="<=1/14/2014">&lt;= 1/14/2014</button>; it basically sets the time of the selected day to end at 23:59:59.</li>
414 <li>Additionally, when <code>endOfDay</code> option is <code>true</code> and using an exact (<code>=</code>) comparison, all times within that selected day will be included - try searching for <button type="button" data-column="4" data-value="=1/20/2014">= 1/20/2014</button> to note that the day include various times.</li>
415 </ul>
416 <br>
417 </li>
418 <li>This example shows how you can add a jQuery UI Datepicker to compare to filter column content.</li>
419 <li>The <code>filter_formatter</code> function provided in the extra "widget-filter-formatter-jui.js" file is used to add this custom control within the filter row.</li>
420 <li>This code follows the <a class="external" href="http://jqueryui.com/datepicker/#default">default functionality</a> example from the jQuery UI docs.</li>
421 <li>Add the following code to apply a datepicker comparison selector to the filter row:<pre class="prettyprint lang-javascript">$(function() {
422
423 $("table").tablesorter({
424 theme: 'jui',
425 // hidden filter input/selects will resize the columns, so try to minimize the change
426 widthFixed : true,
427 // initialize zebra striping and filter widgets
428 widgets: ["zebra", "filter", "uitheme"],
429 widgetOptions : {
430 // jQuery selector string of an element used to reset the filters
431 filter_reset : 'button.reset',
432 // add custom selector elements to the filter row
433 filter_formatter : {
434
435 // Date (one input)
436 4 : function($cell, indx) {
437 return $.tablesorter.filterFormatter.uiDateCompare( $cell, indx, {
438 cellText : 'Dates', // text added before the input
439 compare : [ '', '=', '&gt;=', '&lt;=' ], // search values greater/less than selected value; overrides exactMatch
440 selected : 3, // zero-based index of compare starting selected value
441
442 // add any of the jQuery UI Datepicker options here (http://api.jqueryui.com/datepicker/)
443 // defaultDate : '1/1/2014', // default date
444 changeMonth : true,
445 changeYear : true
446 });
447 }
448 }
449 }
450 });
451
452 });</pre></li>
453 <li>There is one issue with this comparison script, and that is with dates that contain a time:
454 <ul>
455 <li>Table data that contains dates with times will be parsed into values that include time.</li>
456 <li>So if the <code>compare</code> option is set to <code>=</code>, it may not show any filtered table rows as none match that date at midnight. To fix this, either remove times from the table data, use a column parser that ignores the time, or use the Datepicker range selector and set the "from" input to the desired day and the "to" input to be the next day (at midnight).</li>
457 <li><del>Using a <code>compare</code> of <code>&lt;=</code> will only show filtered dates from the selected day <em>at midnight</em> with earlier dates; i.e. a cell with the selected date but a time set to noon will not be visible</del>. As of <span class="version">v2.10/8</span>, the comparison of dates less than the selected date, now adds a time of 11:59:59 so it will include times within the selected date.</li>
458 </ul>
459 </li>
460 </ul>
461 </div>
462
463 <h3><a href="#"><strong>jQuery UI Datepicker Range Selector</strong></a> <span class="xsmall">("Date (two inputs)" column)</span></h3>
464 <div>
465 <ul>
466 <li>In <span class="version">v2.16.0</span>, a <code>filter_placeholder</code> option was added:
467 <ul>
468 <li>The option adds a search input placeholder and select (first option) text, but it also includes placeholder text for both the "from" and "to" inputs</li>
469 <li>Set it as follows:
470 <pre class="prettyprint lang-js">filter_placeholder : {
471 search : '', // any default search inputs including the datepicker comparison
472 from : 'Date from...', // datepicker range "from" placeholder
473 to : 'Date to...' // datepicker range "to" placeholder
474 }
475 </pre></li>
476 <li><span class="label label-info">Note</span> The browser must support the <a href="http://caniuse.com/#feat=input-placeholder">placeholder attribute</a> before this text will be visible.</li>
477 </ul>
478 </li>
479 <li>In <span class="version">v2.15.0</span>, an <code>endOfDay</code> option was added, which when <code>true</code> and searching within one day, all times within that selected day will be included - try searching for <button type="button" data-column="5" data-value="1/20/2014 - 1/20/2014">1/20/2014 - 1/20/2014</button> to note that the day include various times.<br></li>
480 <li>This example shows how you can add a jQuery UI Datepicker range to filter column content.</li>
481 <li>The <code>filter_formatter</code> function provided in the extra "widget-filter-formatter-jui.js" file is used to add this custom control within the filter row.</li>
482 <li>This code follows the <a class="external" href="http://jqueryui.com/datepicker/#date-range">date range</a> example from the jQuery UI docs.</li>
483 <li>Updated two input functions so that if the "to" input is empty, all dates greater than the "from" date are shown. If the "from" input is empty, all dates less than the "to" input date are shown (<span class="version updated">v2.10.1</span>).</li>
484 <li>Add the following code to apply a datepicker range selector to the filter row:<pre class="prettyprint lang-javascript">$(function() {
485
486 $("table").tablesorter({
487 theme: 'jui',
488 // hidden filter input/selects will resize the columns, so try to minimize the change
489 widthFixed : true,
490 // initialize zebra striping and filter widgets
491 widgets: ["zebra", "filter", "uitheme"],
492 widgetOptions : {
493 // jQuery selector string of an element used to reset the filters
494 filter_reset : 'button.reset',
495 // add custom selector elements to the filter row
496 filter_formatter : {
497
498 // Date (two inputs)
499 5 : function($cell, indx) {
500 return $.tablesorter.filterFormatter.uiDatepicker( $cell, indx, {
501 // add any of the jQuery UI Datepicker options here (http://api.jqueryui.com/datepicker/)
502 // from : '8/1/2013', // starting date
503 // to : '1/18/2014', // ending date
504 textFrom: 'from', // "from" label text
505 textTo: 'to', // "to" label text
506 changeMonth: true,
507 changeYear : true
508 });
509 }
510 }
511 }
512 });
513
514 });</pre></li>
515 <li>Note that the datepicker options are slightly different from the default datepicker options:
516 <ul>
517 <li>Instead of using the <code>defaultDate</code> option of the datepicker widget, it has a <code>from</code> and <code>to</code> option to fullfill that purpose.</li>
518 <li>The options added to this function will be applied to both the from and to datepicker inputs.</li>
519 <li>As of <span class="version">v2.10.8</span>, the comparison of dates less than the selected "to" date, now adds a time of 11:59:59 so it will include times within the selected dates.</li>
520 </ul>
521 </li>
522 </ul>
523 </div>
524
525 <h3><a href="#"><strong>Custom Filter Formatter Function Information</strong></a></h3>
526 <div>
527 If you want to write your own custom filter formatter function, there are certain requirements that should be met:
528 <ul>
529 <li>Required input element:
530 <ul>
531 <li>If your selector isn't an input (e.g. jQuery UI Slider), then you'll need to return an input of type hidden which gets updated by the selector with the filter query for the column.
532 <pre class="prettyprint lang-javascript">filter_formatter : {
533 0 : function($cell, indx) {
534 var $input = $('&lt;input type="hidden"&gt;').appendTo($cell);
535 // add your selector code here
536 return $input;
537 }
538 }</pre></li>
539 <li>If the input contains a value that doesn't match a standard filter syntax, then you'll need to return an input of type hidden with the correct format.</li>
540 <li>This returned input element should to be attached to the <code>$cell</code>.</li>
541 <li>The returned input should have a "search" event triggered upon it after being updated.</li>
542 </ul>
543 </li>
544 <li>Some method should be added to show the user the current value of the selector - update a data attribute for css3 tooltips, or update the header cell.</li>
545 <li>A reset function needs to also be included; bind to the <code>filterReset</code> event and clear out or disable your custom selector when triggered.
546 <pre class="prettyprint lang-javascript">$cell.closest('table').bind('filterReset', function() { /* update the input here */ });</pre>
547 </li>
548 <li>In <span class="version">v2.15.0</span>, in order to update your custom input with any saved filter searches, you will need to bind to the <code>filterFomatterUpdate</code> event to get the saved filter value from the hidden input and apply it to your custom input.
549 <pre class="prettyprint lang-javascript">$cell.closest('table').bind('filterFomatterUpdate', function() {
550 var savedSearch = $cell.find('input[type=hidden]').val();
551 // apply this saved search to your custom input
552 $.tablesorter.filter.formatterUpdated($cell, indx); // new v2.17.5
553 });</pre>As of <span class="version">v2.17.5</span>, you need to call <code>$.tablesorter.filter.formatterUpdated($cell, indx);</code> so the filter widget knows when all inputs have completed initialization, and fire the "filterInit" event.<br><br></li>
554 <li>If your selector needs a parsed value to work with, add the <code>filter-parsed</code> class name to the header cell above the filter, use this code to do that:
555 <pre class="prettyprint lang-javascript">$cell.closest('thead').find('th[data-column=' + indx + ']').addClass('filter-parsed');</pre>
556 </li>
557 <li>Since, by default, the filter only matches cell content, a <code>1</code> in the filter will show all rows with a one no matter where it is located. So, if you need an exact match, add an equal sign to the end of the value (<code>1=</code>). This forces the filter to exactly match the value in the search input.</li>
558 <li>To include a search delay, trigger the search on the hidden input and pass a boolean. If <code>true</code> or undefined, the search will be delayed and not delayed if <code>false</code>; modify the delay time set by changing the <code>filter_searchDelay</code> option.
559 <pre class="prettyprint lang-javascript">$input.val( newVal ).trigger('search', false); // no search delay</pre>
560 </li>
561
562 </ul>
563 </div>
564
565 </div>
566
567 <h1>Demo</h1>
568 <div id="switcher"></div>
569 <button type="button" class="reset">Reset Search</button>
570 <br>
571 <div id="demo"><table class="tablesorter">
572 <thead>
573 <tr>
574 <th>Rank</th>
575 <th>Age</th>
576 <th class="total">Total (range)</th>
577 <th>Discount</th>
578 <th data-placeholder="Try 1/18/2013">Date (one input)</th>
579 <th>Date (two inputs; range)</th>
580 </tr>
581 </thead>
582 <tbody>
583 <tr><td>1</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2013 7:22 AM</td><td>Jun 26, 2013 7:22 AM</td></tr>
584 <tr><td>11</td><td>12</td><td>$82.99</td><td>5%</td><td>Aug 21, 2013 12:21 PM</td><td>Aug 21, 2013 12:21 PM</td></tr>
585 <tr><td>12</td><td>51</td><td>$99.29</td><td>18%</td><td>Oct 13, 2013 1:15 PM</td><td>Oct 13, 2013 1:15 PM</td></tr>
586 <tr><td>51</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2013 8:14 AM</td><td>Jul 6, 2013 8:14 AM</td></tr>
587 <tr><td>21</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2012 5:14 AM</td><td>Dec 10, 2012 5:14 AM</td></tr>
588 <tr><td>013</td><td>18</td><td>$65.89</td><td>45%</td><td>Jan 12, 2013 11:14 AM</td><td>Jan 12, 2013 11:14 AM</td></tr>
589 <tr><td>005</td><td>45</td><td>$153.19</td><td>45%</td><td>Jan 18, 2014 9:12 AM</td><td>Jan 18, 2014 9:12 AM</td></tr>
590 <tr><td>10</td><td>3</td><td>$5.29</td><td>4%</td><td>Jan 8, 2013 5:11 PM</td><td>Jan 8, 2013 5:11 PM</td></tr>
591 <tr><td>16</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2014 11:23 AM</td><td>Jan 14, 2014 11:23 AM</td></tr>
592 <tr><td>66</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2013 9:12 AM</td><td>Jan 18, 2013 9:12 AM</td></tr>
593 <tr><td>100</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2013 7:23 PM</td><td>Feb 12, 2013 7:23 PM</td></tr>
594 <tr><td>55</td><td>65</td><td>$123.00</td><td>32%</td><td>Jan 20, 2014 1:12 PM</td><td>Jan 20, 2014 1:12 PM</td></tr>
595 <tr><td>9</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2013 10:55 AM</td><td>Jun 11, 2013 10:55 AM</td></tr>
596 <tr><td>13</td><td>12</td><td>$19.99</td><td>18%</td><td>Jan 20, 2014 7:45 PM</td><td>Jan 20, 2014 7:45 PM</td></tr>
597 <tr><td>73</td><td>58</td><td>$129.19</td><td>39%</td><td>Jan 20, 2014 10:11 AM</td><td>Jan 20, 2014 10:11 AM</td></tr>
598 </tbody>
599 </table></div>
600
601 <h1>Page Header</h1>
602 <div>
603 <pre class="prettyprint lang-html">&lt;!-- jQuery UI for range slider --&gt;
604 &lt;link rel="stylesheet" href="css/jquery-ui.min.css"&gt;
605 &lt;script src="js/jquery-ui.min.js"&gt;&lt;/script&gt;
606
607 &lt;!-- tablesorter plugin --&gt;
608 &lt;link rel=&quot;stylesheet&quot; href=&quot;../css/theme.blue.css&quot;&gt;
609 &lt;script src=&quot;../js/jquery.tablesorter.js&quot;&gt;&lt;/script&gt;
610 &lt;script src=&quot;../js/jquery.tablesorter.widgets.js&quot;&gt;&lt;/script&gt;
611
612 &lt;!-- filter formatter code --&gt;
613 &lt;link rel=&quot;stylesheet&quot; href=&quot;../css/filter.formatter.css&quot;&gt;
614 &lt;script src=&quot;../js/widgets/widget-filter-formatter-jui.js&quot;&gt;&lt;/script&gt;</pre>
615 </div>
616
617 <h1>CSS</h1>
618 <div id="css">
619 <pre class="prettyprint lang-css"></pre>
620 </div>
621
622 <h1>Javascript</h1>
623 <div id="javascript">
624 <pre class="prettyprint lang-javascript"></pre>
625 </div>
626
627 <h1>HTML</h1>
628 <div id="html">
629 <pre class="prettyprint lang-html"></pre>
630 </div>
631
632 <div class="next-up">
633 <hr />
634 Next up: <a href="example-widget-filter-formatter-2.html">jQuery custom filter widget formatter (HTML5 Elements) &rsaquo;&rsaquo;</a>
635 </div>
636
637 </div>
638
639 </body>
640 </html>