| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Custom Filter Widget Formatter (HTML5 Elements)</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 |
|
| 18 |
|
| 19 |
<link href="../css/theme.blue.css" rel="stylesheet"> |
| 20 |
<link href="../css/filter.formatter.css" rel="stylesheet"> |
| 21 |
<script src="../js/jquery.tablesorter.js"></script> |
| 22 |
<script src="../js/jquery.tablesorter.widgets.js"></script> |
| 23 |
<script src="../js/widgets/widget-filter-formatter-html5.js"></script> |
| 24 |
|
| 25 |
<style id="css">/* css needed to get compare selector & slider in-line */ |
| 26 |
.compare-select-wrapper { width: 60%; float: right; }</style> |
| 27 |
|
| 28 |
<script id="js">$(function() { |
| 29 |
|
| 30 |
$("table").tablesorter({ |
| 31 |
theme: 'blue', |
| 32 |
// hidden filter input/selects will resize the columns, so try to minimize the change |
| 33 |
widthFixed : true, |
| 34 |
// initialize zebra striping and filter widgets |
| 35 |
widgets: ["zebra", "filter", "stickyHeaders"], |
| 36 |
widgetOptions : { |
| 37 |
// Use the $.tablesorter.storage utility to save the most recent filters |
| 38 |
filter_saveFilters : true, |
| 39 |
// jQuery selector string of an element used to reset the filters |
| 40 |
filter_reset : 'button.reset', |
| 41 |
// add custom selector elements to the filter row |
| 42 |
filter_formatter : { |
| 43 |
|
| 44 |
// Rank |
| 45 |
0 : function($cell, indx) { |
| 46 |
return $.tablesorter.filterFormatter.html5Range( $cell, indx, { |
| 47 |
value: 0, |
| 48 |
min: 0, |
| 49 |
max: 100, |
| 50 |
delayed: true, |
| 51 |
valueToHeader: true, |
| 52 |
compare : [ '=', '>=', '<=' ], |
| 53 |
selected: 1 |
| 54 |
}); |
| 55 |
}, |
| 56 |
|
| 57 |
// Color |
| 58 |
1 : function($cell, indx) { |
| 59 |
return $.tablesorter.filterFormatter.html5Color( $cell, indx, { |
| 60 |
value: '#000000', |
| 61 |
addToggle: true, |
| 62 |
exactMatch: true, |
| 63 |
valueToHeader: false |
| 64 |
}); |
| 65 |
}, |
| 66 |
|
| 67 |
// Age |
| 68 |
3: function($cell, indx) { |
| 69 |
return $.tablesorter.filterFormatter.html5Number( $cell, indx, { |
| 70 |
value: 1, |
| 71 |
min: 1, |
| 72 |
max: 65, |
| 73 |
delayed: true, |
| 74 |
addToggle: true, |
| 75 |
exactMatch: true, |
| 76 |
compare: '' |
| 77 |
}); |
| 78 |
}, |
| 79 |
|
| 80 |
// Total |
| 81 |
4 : function($cell, indx) { |
| 82 |
return $.tablesorter.filterFormatter.html5Range( $cell, indx, { |
| 83 |
value: 0, |
| 84 |
min: 0, |
| 85 |
max: 150, |
| 86 |
delayed: true, |
| 87 |
valueToHeader: true, |
| 88 |
compare : '>=' |
| 89 |
}); |
| 90 |
}, |
| 91 |
|
| 92 |
// Discount |
| 93 |
5: function($cell, indx) { |
| 94 |
return $.tablesorter.filterFormatter.html5Number( $cell, indx, { |
| 95 |
value: 1, |
| 96 |
min: 1, |
| 97 |
max: 44, |
| 98 |
delayed: true, |
| 99 |
addToggle: false, |
| 100 |
compare: [ '<=', '=', '>=' ], |
| 101 |
selected: 2 |
| 102 |
}); |
| 103 |
} |
| 104 |
|
| 105 |
} |
| 106 |
} |
| 107 |
}); |
| 108 |
|
| 109 |
});</script> |
| 110 |
|
| 111 |
</head> |
| 112 |
<body> |
| 113 |
<div id="banner"> |
| 114 |
<h1>table<em>sorter</em></h1> |
| 115 |
<h2>Custom Filter Widget Formatter (HTML5 Elements)</h2> |
| 116 |
<h3>Flexible client-side table sorting</h3> |
| 117 |
<a href="index.html">Back to documentation</a> |
| 118 |
</div> |
| 119 |
<div id="main"> |
| 120 |
|
| 121 |
<p></p> |
| 122 |
<br> |
| 123 |
<div class="accordion"> |
| 124 |
|
| 125 |
<h3><a href="#">Notes</a></h3> |
| 126 |
<div> |
| 127 |
<ul> |
| 128 |
<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> |
| 129 |
<li>As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.</li> |
| 130 |
<li>At this time, these widgets do not work with the sticky header widget.</li> |
| 131 |
<li>This page shows you how to add a few default <strong>HTML5 elements</strong> to interact with the filter widget.</li> |
| 132 |
<li>If the HTML5 elements are not supported by your browser, you'll just see an input.</li> |
| 133 |
<li>Custom filter widget option <code>filter_formatter</code> was added in version 2.7.7.</li> |
| 134 |
<li>jQuery v1.4.3+ required.</li> |
| 135 |
</ul> |
| 136 |
</div> |
| 137 |
|
| 138 |
<h3><a href="#"><strong>HTML Range</strong></a> <span class="xsmall">("Rank" and "Total" columns)</span></h3> |
| 139 |
<div> |
| 140 |
<ul> |
| 141 |
<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> |
| 142 |
<li>This example shows how you can add an HTML5 range input slider to filter column content.</li> |
| 143 |
<li>The <code>filter_formatter</code> function provided in the extra "widget-filter-formatter-html5.js" file is used to add this custom control within the filter row.</li> |
| 144 |
<li>Make sure to include all values within the selected range, otherwise rows outside of this range will be forever hidden.</li> |
| 145 |
<li>Add the following code to apply an HTML5 range slider to the filter row:<pre class="prettyprint lang-javascript">$(function() { |
| 146 |
|
| 147 |
$("table").tablesorter({ |
| 148 |
theme: 'blue', |
| 149 |
// initialize zebra striping and filter widgets |
| 150 |
widgets: ["zebra", "filter"], |
| 151 |
widgetOptions : { |
| 152 |
// jQuery selector string of an element used to reset the filters |
| 153 |
filter_reset : 'button.reset', |
| 154 |
// add custom selector elements to the filter row |
| 155 |
filter_formatter : { |
| 156 |
|
| 157 |
// Rank |
| 158 |
0 : function($cell, indx) { |
| 159 |
return $.tablesorter.filterFormatter.html5Range( $cell, indx, { |
| 160 |
value: 0, |
| 161 |
min: 0, |
| 162 |
max: 100, |
| 163 |
delayed: true, |
| 164 |
valueToHeader: true, |
| 165 |
compare : [ '=', '>=', '<=' ], |
| 166 |
selected: 1 |
| 167 |
}); |
| 168 |
}, |
| 169 |
|
| 170 |
// Total |
| 171 |
4 : function($cell, indx) { |
| 172 |
return $.tablesorter.filterFormatter.html5Range( $cell, indx, { |
| 173 |
value: 0, |
| 174 |
min: 0, |
| 175 |
max: 150, |
| 176 |
delayed: true, |
| 177 |
valueToHeader: true, |
| 178 |
compare : '>=' |
| 179 |
}); |
| 180 |
} |
| 181 |
|
| 182 |
} |
| 183 |
} |
| 184 |
}); |
| 185 |
|
| 186 |
});</pre></li> |
| 187 |
<li>By default, this code has the <code>valueToHeader</code> option set to <code>true</code> to add the slider value to the header cell above the filter.</li> |
| 188 |
<li>The tooltip above the slider is NOT added in this example because the slider handle is not a separate element. But if you are interested, you can use <a href="http://codepen.io/chriscoyier/pen/lokyH">this code</a> by Chris Coyier to animate a range slider bubble.</li> |
| 189 |
<li>Another option named <code>exactMatch</code> was added to allow exact or general matching of column content.</li> |
| 190 |
<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> |
| 191 |
<li>A search delay option 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> |
| 192 |
</ul> |
| 193 |
</div> |
| 194 |
|
| 195 |
<h3><a href="#"><strong>HTML5 color input</strong></a> <span class="xsmall">("Color" column)</span></h3> |
| 196 |
<div> |
| 197 |
<ul> |
| 198 |
<li>This example shows how you can add an HTML5 color input to filter column content.</li> |
| 199 |
<li>The <code>filter_formatter</code> function is used to add a custom control within the filter row, but a hidden input is still required to store the filter value.</li> |
| 200 |
<li>Add the following code to apply a color input to the filter row:<pre class="prettyprint lang-javascript">$(function() { |
| 201 |
|
| 202 |
$("table").tablesorter({ |
| 203 |
theme: 'blue', |
| 204 |
// hidden filter input/selects will resize the columns, so try to minimize the change |
| 205 |
widthFixed : true, |
| 206 |
// initialize zebra striping and filter widgets |
| 207 |
widgets: ["zebra", "filter"], |
| 208 |
widgetOptions : { |
| 209 |
// jQuery selector string of an element used to reset the filters |
| 210 |
filter_reset : 'button.reset', |
| 211 |
// add custom selector elements to the filter row |
| 212 |
filter_formatter : { |
| 213 |
|
| 214 |
// Color |
| 215 |
1 : function($cell, indx) { |
| 216 |
return $.tablesorter.filterFormatter.html5Color( $cell, indx, { |
| 217 |
value: '#000000', |
| 218 |
addToggle: true, |
| 219 |
exactMatch: true, |
| 220 |
valueToHeader: false |
| 221 |
}); |
| 222 |
} |
| 223 |
|
| 224 |
} |
| 225 |
} |
| 226 |
}); |
| 227 |
|
| 228 |
});</pre></li> |
| 229 |
<li>This color selector will only output the color as a hex value with a hash followed by six characters (<code>#000000</code>).</li> |
| 230 |
<li>By default, this code has the <code>valueToHeader</code> option set to <code>false</code>. The currently selected color is added to a span within the cell by default.</li> |
| 231 |
<li>Another option named <code>exactMatch</code> was added to allow exact or general matching of column content, in case you have multiple colors in one cell.</li> |
| 232 |
<li>This selector 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> |
| 233 |
</ul> |
| 234 |
</div> |
| 235 |
|
| 236 |
<h3><a href="#"><strong>HTML5 Number Selector</strong></a> <span class="xsmall">("Age" and "Discount" columns)</span></h3> |
| 237 |
<div> |
| 238 |
<ul> |
| 239 |
<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> |
| 240 |
<li>This example shows how you can add an HTML5 number spinner to the filter column content.</li> |
| 241 |
<li>The <code>filter_formatter</code> function provided in the extra "widget-filter-formatter-html5.js" file is used to add this custom control within the filter row.</li> |
| 242 |
<li>Add the following code to apply an HTML spinner to filter a column:<pre class="prettyprint lang-javascript">$(function() { |
| 243 |
|
| 244 |
$("table").tablesorter({ |
| 245 |
theme: 'blue', |
| 246 |
// hidden filter input/selects will resize the columns, so try to minimize the change |
| 247 |
widthFixed : true, |
| 248 |
// initialize zebra striping and filter widgets |
| 249 |
widgets: ["zebra", "filter"], |
| 250 |
widgetOptions : { |
| 251 |
// jQuery selector string of an element used to reset the filters |
| 252 |
filter_reset : 'button.reset', |
| 253 |
// add custom selector elements to the filter row |
| 254 |
filter_formatter : { |
| 255 |
|
| 256 |
// Age |
| 257 |
3: function($cell, indx) { |
| 258 |
return $.tablesorter.filterFormatter.html5Number( $cell, indx, { |
| 259 |
value: 1, |
| 260 |
min: 1, |
| 261 |
max: 65, |
| 262 |
delayed: true, |
| 263 |
addToggle: true, |
| 264 |
exactMatch: true, |
| 265 |
compare: '' |
| 266 |
}); |
| 267 |
}, |
| 268 |
|
| 269 |
// Discount |
| 270 |
5: function($cell, indx) { |
| 271 |
return $.tablesorter.filterFormatter.html5Number( $cell, indx, { |
| 272 |
value: 1, |
| 273 |
min: 1, |
| 274 |
max: 44, |
| 275 |
delayed: true, |
| 276 |
addToggle: false, |
| 277 |
compare: [ '<=', '=', '>=' ], |
| 278 |
selected: 2 |
| 279 |
}); |
| 280 |
} |
| 281 |
|
| 282 |
} |
| 283 |
} |
| 284 |
}); |
| 285 |
|
| 286 |
});</pre></li> |
| 287 |
<li>This is spinner 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> |
| 288 |
<li>Another option named <code>exactMatch</code> was added to allow exact or general matching of column content.</li> |
| 289 |
<li>A search delay option 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> |
| 290 |
</ul> |
| 291 |
</div> |
| 292 |
|
| 293 |
</div> |
| 294 |
|
| 295 |
<h1>Demo</h1> |
| 296 |
<button type="button" class="reset">Reset Search</button> |
| 297 |
<div id="demo"><table class="tablesorter"> |
| 298 |
<thead> |
| 299 |
<tr><th>Rank</th><th>Color</th><th>Name</th><th>Age</th><th>Total</th><th>Discount</th><th>Date</th></tr> |
| 300 |
</thead> |
| 301 |
<tbody> |
| 302 |
<tr><td>1</td><td>#ff0000</td><td>Johnson</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2013 7:22 AM</td></tr> |
| 303 |
<tr><td>11</td><td>#00ff00</td><td>Hibert</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2013 12:21 PM</td></tr> |
| 304 |
<tr><td>12</td><td>#0000ff</td><td>Henry</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2013 1:15 PM</td></tr> |
| 305 |
<tr><td>51</td><td>#00ff00</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2013 8:14 AM</td></tr> |
| 306 |
<tr><td>21</td><td>#ffffff</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2012 5:14 AM</td></tr> |
| 307 |
<tr><td>013</td><td>#ff0000</td><td>Kent</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2013 11:14 AM</td></tr> |
| 308 |
<tr><td>005</td><td>#00ff00</td><td>Bruce</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2014 9:12 AM</td></tr> |
| 309 |
<tr><td>10</td><td>#000000</td><td>Alex</td><td>3</td><td>$5.29</td><td>4%</td><td>Jan 8, 2013 5:11 PM</td></tr> |
| 310 |
<tr><td>16</td><td>#ff0000</td><td>Franco</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2014 11:23 AM</td></tr> |
| 311 |
<tr><td>66</td><td>#000000</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2013 9:12 AM</td></tr> |
| 312 |
<tr><td>100</td><td>#ffffff</td><td>Brenda</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2013 7:23 PM</td></tr> |
| 313 |
<tr><td>55</td><td>#000000</td><td>Bronson</td><td>65</td><td>$123.00</td><td>32%</td><td>Jan 20, 2014 1:12 PM</td></tr> |
| 314 |
<tr><td>9</td><td>#000000</td><td>Martha</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2013 10:55 AM</td></tr> |
| 315 |
</tbody> |
| 316 |
</table></div> |
| 317 |
|
| 318 |
<h1>Page Header</h1> |
| 319 |
<div> |
| 320 |
<pre class="prettyprint lang-html"><!-- jQuery UI for range slider --> |
| 321 |
<link rel="stylesheet" href="css/jquery-ui.min.css"> |
| 322 |
<script src="js/jquery-ui.min.js"></script> |
| 323 |
|
| 324 |
<!-- tablesorter plugin --> |
| 325 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 326 |
<script src="../js/jquery.tablesorter.js"></script> |
| 327 |
<script src="../js/jquery.tablesorter.widgets.js"></script> |
| 328 |
|
| 329 |
<!-- filter formatter code --> |
| 330 |
<link rel="stylesheet" href="../css/filter.formatter.css"> |
| 331 |
<script src="../js/widgets/widget-filter-formatter-html5.js"></script></pre> |
| 332 |
</div> |
| 333 |
|
| 334 |
<h1>Javascript</h1> |
| 335 |
<div id="javascript"> |
| 336 |
<pre class="prettyprint lang-javascript"></pre> |
| 337 |
</div> |
| 338 |
|
| 339 |
<h1>HTML</h1> |
| 340 |
<div id="html"> |
| 341 |
<pre class="prettyprint lang-html"></pre> |
| 342 |
</div> |
| 343 |
|
| 344 |
<div class="next-up"> |
| 345 |
<hr /> |
| 346 |
Next up: <a href="example-widget-ui-theme.html">UITheme widget - jQuery UI theme ››</a> |
| 347 |
</div> |
| 348 |
|
| 349 |
</div> |
| 350 |
|
| 351 |
</body> |
| 352 |
</html> |