| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Custom Filter Widget Search Type (example 2)</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/jquery.tablesorter.widgets.js"></script> |
| 26 |
<script src="../js/widgets/widget-filter-type-insideRange.js"></script> |
| 27 |
<script src="../js/parsers/parser-date-range.js"></script> |
| 28 |
|
| 29 |
<script id="js">$(function() { |
| 30 |
|
| 31 |
// call the tablesorter plugin |
| 32 |
$("#table").tablesorter({ |
| 33 |
theme: 'blue', |
| 34 |
widthFixed : true, |
| 35 |
widgets: ["zebra", "filter"], |
| 36 |
widgetOptions : { |
| 37 |
filter_reset : '.reset', |
| 38 |
// set to false because it is difficult to determine if a filtered |
| 39 |
// row is already showing when looking at ranges |
| 40 |
filter_searchFiltered : false |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
});</script> |
| 45 |
|
| 46 |
<script> |
| 47 |
$(function() { |
| 48 |
$('button').on('click', function() { |
| 49 |
var $this = $(this), |
| 50 |
filters = [], |
| 51 |
col = $(this).data('column'), |
| 52 |
query = $(this).text(); |
| 53 |
filters[col] = query; |
| 54 |
$('table').trigger('search', [ filters ]); |
| 55 |
}); |
| 56 |
}); |
| 57 |
|
| 58 |
</script> |
| 59 |
|
| 60 |
</head> |
| 61 |
<body> |
| 62 |
<div id="banner"> |
| 63 |
<h1>table<em>sorter</em></h1> |
| 64 |
<h2>Custom Filter Widget Search Type (example 2)</h2> |
| 65 |
<h3>Flexible client-side table sorting</h3> |
| 66 |
<a href="index.html">Back to documentation</a> |
| 67 |
</div> |
| 68 |
<div id="main"> |
| 69 |
|
| 70 |
<p class="tip"> |
| 71 |
<em>NOTE!</em> |
| 72 |
<ul> |
| 73 |
<li>In <span class="version updated">v2.21.0</span> |
| 74 |
<ul> |
| 75 |
<li>The "insideRange" function was updated to use the column parser and moved into a separate file "widget-filter-type-insideRange.js"</li> |
| 76 |
<li>This change would allow the sorting of dates, if using it along with one of the <a href="example-parsers-date-range.html">date-range parsers</a> (added v2.21.0).</li> |
| 77 |
</ul> |
| 78 |
</li> |
| 79 |
<li>This is another example of how to add a custom filter search type - see <a href="example-widget-filter-custom-search.html#how_to_add_custom_filter_types">this page</a> for details on how to add your own.</li> |
| 80 |
<li>This "insideRange" search type does the following: |
| 81 |
<ul> |
| 82 |
<li>This search type was not included with the other <a href="example-widget-filter-custom-search.html#builtin_filters">built-in search types</a> as it might be a little slower than the other search types because it has a bit more calculation to do than the others.</li> |
| 83 |
<li>It looks for a dash surrounded by spaces (<code> - </code>) within the filter before activating.</li> |
| 84 |
<li>So if you look for just <button type="button" data-column="2">4</button> in the "Delivery" column, the exact match of 4 will still be included.</li> |
| 85 |
<li>Test out some more examples: |
| 86 |
<ul> |
| 87 |
<li>Try <button type="button" data-column="2">7</button> or <button type="button" data-column="2">8</button> in the Delivery column</li> |
| 88 |
<li><button type="button" data-column="3">$15.45</button> in the "Price Range" column.</li> |
| 89 |
<li><button type="button" data-column="4">7/12/2014</button> in the "Date Range" column; this column is processed using the "date-range-mdy" parser (added <span class="version">v2.21.0</span>).</li> |
| 90 |
</ul> |
| 91 |
</li> |
| 92 |
</ul> |
| 93 |
</li> |
| 94 |
<li>Entering a range (e.g. <button type="button" data-column="2">4 - 7</button> will switch the query to the <a href="example-widget-filter-custom-search.html#builtin_filters">range search type</a> which will <em>only look at the first number</em> of the range within each cell.</li> |
| 95 |
</ul> |
| 96 |
</p> |
| 97 |
|
| 98 |
<h1>Demo</h1> |
| 99 |
Filters: <button type="button">Reset</button> |
| 100 |
<table id="table" class="tablesorter"> |
| 101 |
<thead> |
| 102 |
<tr> |
| 103 |
<th>Rank</th> |
| 104 |
<th>Name</th> |
| 105 |
<th>Delivery (days)</th> |
| 106 |
<th>Price Range</th> |
| 107 |
<th class="sorter-date-range-mdy">Date Range</th> |
| 108 |
</tr> |
| 109 |
</thead> |
| 110 |
<tbody> |
| 111 |
<tr><td>1</td><td>Widget</td><td>2 - 10</td><td>$5.95 - $13.20</td><td>04/28/2014 - 07/13/2014</td></tr> |
| 112 |
<tr><td>11</td><td>Doodad</td><td>1 - 4</td><td>$2.99 - $8.40</td><td>04/28/2014 - 05/13/2014</td></tr> |
| 113 |
<tr><td>12</td><td>Whatchamacallit</td><td>3 - 7</td><td>$4.29 - $15.99</td><td>7/15/2014</td></tr> |
| 114 |
<tr><td>15</td><td>Thingy</td><td>5 - 6</td><td>$9.99 - $13.20</td><td>07/12/2014 - 07/23/2014</td></tr> |
| 115 |
<tr><td>21</td><td>Cube</td><td>2 - 7</td><td>$6.99 - $14.99</td><td>05/22/2014 - 05/23/2014</td></tr> |
| 116 |
<tr><td>13</td><td>It</td><td>5 - 12</td><td>$15.89 - $18.22</td><td>8/12/2014 - 7/10/2014</td></tr> |
| 117 |
|
| 118 |
<tr><td>5</td><td>Fred</td><td>20 - 30</td><td>$13.19 - $15.54</td><td>6/12/2014 - 6/14/2014</td></tr> |
| 119 |
<tr><td>10</td><td>FuBar</td><td>4</td><td>$5.50</td><td>6/13/2014 - 6/22/2014</td></tr> |
| 120 |
<tr><td>16</td><td>Otto</td><td>2 - 4</td><td>$6.30 - $14.19</td><td>5/10/2014 - 5/20/2014</td></tr> |
| 121 |
<tr><td>21</td><td>Betsy</td><td>7</td><td>$5.67 - $8.25</td><td>6/2/2014 - 6/13/2014</td></tr> |
| 122 |
<tr><td>18</td><td>Clyde</td><td>5 - 10</td><td>$11.20 - $15.45</td><td>6/13/2014</td></tr> |
| 123 |
<tr><td>7</td><td>Brick</td><td>5 - 7</td><td>$12.00 - $14.30</td><td>7/2/2014 - 7/25/2014</td></tr> |
| 124 |
<tr><td>9</td><td>Gadget</td><td>10 - 20</td><td>$7.09 - $13.20</td><td>5/23/2014 - 6/12/2014</td></tr> |
| 125 |
</tbody> |
| 126 |
</table> |
| 127 |
|
| 128 |
<h1>Page Head</h1> |
| 129 |
<div id="html"> |
| 130 |
<pre class="prettyprint lang-html"><!-- jQuery --> |
| 131 |
<script src="js/jquery-latest.min.js"></script> |
| 132 |
|
| 133 |
<!-- tablesorter --> |
| 134 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 135 |
<script src="../js/jquery.tablesorter.js"></script> |
| 136 |
<script src="../js/jquery.tablesorter.widgets.js"></script> |
| 137 |
<!-- inside range filter type --> |
| 138 |
<script src="../js/widgets/widget-filter-type-insideRange.js"></script> |
| 139 |
<!-- parse date ranges --> |
| 140 |
<script src="../js/parsers/parser-date-range.js"></script></pre> |
| 141 |
</div> |
| 142 |
|
| 143 |
|
| 144 |
<h1>Javascript</h1> |
| 145 |
<div id="javascript"> |
| 146 |
<pre class="prettyprint lang-javascript"></pre> |
| 147 |
</div> |
| 148 |
|
| 149 |
<div class="next-up"> |
| 150 |
<hr /> |
| 151 |
Next up: <a href="example-widget-filter-formatter-1.html">jQuery custom filter widget formatter (jQuery UI widgets) ››</a> |
| 152 |
</div> |
| 153 |
|
| 154 |
</div> |
| 155 |
|
| 156 |
</body> |
| 157 |
</html> |