| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Toggle 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 |
<link href="css/tipsy.css" rel="stylesheet"> |
| 16 |
|
| 17 |
<script src="js/prettify.js"></script> |
| 18 |
<script src="js/docs.js"></script> |
| 19 |
<script src="js/jquery.tipsy.min.js"></script> |
| 20 |
|
| 21 |
|
| 22 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 23 |
<script src="../js/jquery.tablesorter.js"></script> |
| 24 |
<script src="../js/widgets/widget-filter.js"></script> |
| 25 |
<script src="../js/widgets/widget-headerTitles.js"></script> |
| 26 |
<script src="../js/widgets/widget-toggle.js"></script> |
| 27 |
|
| 28 |
<script id="js">$( function() { |
| 29 |
|
| 30 |
var $table = $( '#table' ), |
| 31 |
isEnabled = true, // tablesorter enabled |
| 32 |
hideFilterRow = false, // hide filter row setting |
| 33 |
|
| 34 |
// used by headerTitles widget |
| 35 |
updateTooltips = function( $cell, txt ) { |
| 36 |
if ( $cell.is( ':hover' ) ) { |
| 37 |
$cell |
| 38 |
.attr({ title : txt, 'original-title' : txt }) |
| 39 |
// hide, then show the tooltip to force updating & realignment |
| 40 |
.tipsy( 'hide' ) |
| 41 |
.tipsy( 'show' ); |
| 42 |
} |
| 43 |
return txt; |
| 44 |
}; |
| 45 |
|
| 46 |
$table.tablesorter({ |
| 47 |
theme : 'blue', |
| 48 |
widthFixed : true, |
| 49 |
widgets : [ 'zebra', 'filter', 'headerTitles', 'toggle-ts' ], |
| 50 |
widgetOptions : { |
| 51 |
filter_reset : '.reset', |
| 52 |
filter_external : '.search', |
| 53 |
filter_columnFilters : true, |
| 54 |
headerTitle_useAria : true, |
| 55 |
headerTitle_tooltip : 'tooltip', |
| 56 |
headerTitle_callback : updateTooltips, |
| 57 |
|
| 58 |
// toggle-ts widget |
| 59 |
toggleTS_hideFilterRow : hideFilterRow, |
| 60 |
toggleTS_callback : function( c, isEnabled ) { |
| 61 |
// update tooltips |
| 62 |
c.$table.trigger( 'refreshHeaderTitle' ); |
| 63 |
} |
| 64 |
} |
| 65 |
}); |
| 66 |
|
| 67 |
// enable/disable tablesorter button |
| 68 |
$( '.toggle' ).click( function() { |
| 69 |
isEnabled = !isEnabled; |
| 70 |
$( this ).text( isEnabled ? 'Disable' : 'Enable' ); |
| 71 |
$table.trigger( isEnabled ? 'enable' : 'disable' ); |
| 72 |
|
| 73 |
// If using the pager: |
| 74 |
// $table.trigger( ( isEnabled ? 'enable' : 'disable' ) + 'Pager' ); |
| 75 |
|
| 76 |
// To reset sort or filter, include the following |
| 77 |
// if ( !isEnabled ) { |
| 78 |
// $table.trigger( 'sortReset' ).trigger( 'filterReset' ); |
| 79 |
// } |
| 80 |
}); |
| 81 |
|
| 82 |
// demo: toggle filter row option |
| 83 |
$( '.filterRow' ).click( function() { |
| 84 |
hideFilterRow = !hideFilterRow; |
| 85 |
$table[ 0 ].config.widgetOptions.toggleTS_hideFilterRow = hideFilterRow; |
| 86 |
$( this ).text( '' + hideFilterRow ); |
| 87 |
}); |
| 88 |
|
| 89 |
// add tooltip |
| 90 |
$( '.tooltip' ).tipsy({ gravity: 's' }); |
| 91 |
|
| 92 |
});</script> |
| 93 |
|
| 94 |
</head> |
| 95 |
<body> |
| 96 |
<div id="banner"> |
| 97 |
<h1>table<em>sorter</em></h1> |
| 98 |
<h2>Toggle Sort & Filter Widget</h2> |
| 99 |
<h3>Flexible client-side table sorting</h3> |
| 100 |
<a href="index.html">Back to documentation</a> |
| 101 |
</div> |
| 102 |
<div id="main"> |
| 103 |
|
| 104 |
<p></p> |
| 105 |
<br> |
| 106 |
<div id="root" class="accordion"> |
| 107 |
|
| 108 |
<h3 id="notes"><a href="#">Notes</a></h3> |
| 109 |
<div> |
| 110 |
<ul> |
| 111 |
<li>This widget allows the enabling or disabling of tablesorter sorting & filtering.</li> |
| 112 |
<li>The widget does not reset an applied sort or filters. If you want to include this when disabling, use the following code: |
| 113 |
<ul> |
| 114 |
<li><a href="index.html#sortreset-method">Sort reset</a>: <code class="prettyprint lang-js">$('table').trigger('sortReset');</code></li> |
| 115 |
<li><a href="example-widget-filter.html#method-reset">Filter reset</a>: <code class="prettyprint lang-js">$('table').trigger('filterReset');</code></li> |
| 116 |
</ul> |
| 117 |
<br> |
| 118 |
</li> |
| 119 |
<li><span class="label alert">*ALERT*</span> This widget requires tablesorter v2.22.4+ and jQuery 1.7+</li> |
| 120 |
</ul> |
| 121 |
</div> |
| 122 |
|
| 123 |
<h3><a href="#">Options</a></h3> |
| 124 |
<div> |
| 125 |
<div> |
| 126 |
<span class="label label-info">TIP!</span> Click on the link in the option 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. |
| 127 |
</div> |
| 128 |
<table class="options tablesorter-blue" data-sortlist="[[0,0]]"> |
| 129 |
<thead> |
| 130 |
<tr><th>Option</th><th class="defaults">Default</th><th class="sorter-false">Description</th></tr> |
| 131 |
</thead> |
| 132 |
<tbody> |
| 133 |
|
| 134 |
<tr id="togglets_hidefilterrow"> |
| 135 |
<td><span class="permalink">toggleTS_hideFilterRow</span></td> |
| 136 |
<td>false</td> |
| 137 |
<td>If <code>true</code>, hide filter row; when <code>false</code>, associated filters are disabled.</td> |
| 138 |
</tr> |
| 139 |
|
| 140 |
<tr id="togglets_callback"> |
| 141 |
<td><a href="#" class="permalink">toggleTS_callback</a></td> |
| 142 |
<td>null</td> |
| 143 |
<td>This function is called after tablesorter has been enabled or disabled. |
| 144 |
<div class="collapsible"> |
| 145 |
<p>Use it as follows:</p> |
| 146 |
<pre class="prettyprint lang-js">$( function() { |
| 147 |
$( 'table' ).tablesorter({ |
| 148 |
widget : [ 'toggle-ts' ], |
| 149 |
widgetOptions : { |
| 150 |
toggleTS_callback : function( c, isEnabled ) { |
| 151 |
c.$table.toggleClass( 'isDisabled', !isEnabled ); |
| 152 |
} |
| 153 |
} |
| 154 |
}); |
| 155 |
});</pre> |
| 156 |
</div> |
| 157 |
</td> |
| 158 |
</tr> |
| 159 |
|
| 160 |
</tbody> |
| 161 |
</table> |
| 162 |
</div> |
| 163 |
|
| 164 |
</div> |
| 165 |
|
| 166 |
<p></p> |
| 167 |
<h1>Demo</h1> |
| 168 |
|
| 169 |
<div id="demo"><p> |
| 170 |
Tablesorter & Filter: <button type="button" class="toggle">Disable</button> |
| 171 |
Hide Filter Row: <button type="button" class="filterRow">false</button> |
| 172 |
</p> |
| 173 |
|
| 174 |
Filter any column: <input class="search" type="search" data-column="any"> |
| 175 |
|
| 176 |
<p>Filter <button type="button" class="reset">Reset</button> (this works even if tablesorter & filter are disabled)</p> |
| 177 |
|
| 178 |
<table id="table" class="tablesorter"> |
| 179 |
<thead> |
| 180 |
<tr> |
| 181 |
<th>Rank</th> |
| 182 |
<th data-value="e">First Name</th> |
| 183 |
<th>Last Name</th> |
| 184 |
<th>Age</th> |
| 185 |
<th class="filter-false">Total (filter disabled)</th> |
| 186 |
<th class="sorter-false">Discount (sort disabled)</th> |
| 187 |
<th>Date</th> |
| 188 |
</tr> |
| 189 |
</thead> |
| 190 |
<tbody> |
| 191 |
<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> |
| 192 |
<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> |
| 193 |
<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> |
| 194 |
<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> |
| 195 |
<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> |
| 196 |
<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> |
| 197 |
<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> |
| 198 |
<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> |
| 199 |
<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> |
| 200 |
<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> |
| 201 |
<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> |
| 202 |
<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> |
| 203 |
<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> |
| 204 |
</tbody> |
| 205 |
</table></div> |
| 206 |
|
| 207 |
<h1>Javascript</h1> |
| 208 |
<div id="javascript"> |
| 209 |
<pre class="prettyprint lang-javascript"></pre> |
| 210 |
</div> |
| 211 |
|
| 212 |
<h1>HTML</h1> |
| 213 |
<div id="html"> |
| 214 |
<pre class="prettyprint lang-html"></pre> |
| 215 |
</div> |
| 216 |
|
| 217 |
</div> |
| 218 |
|
| 219 |
</body> |
| 220 |
</html> |