| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Save Sort Widget</title> |
| 6 |
|
| 7 |
|
| 8 |
<script src="js/jquery-1.4.4.min.js"></script> |
| 9 |
|
| 10 |
|
| 11 |
<link rel="stylesheet" href="css/jq.css"> |
| 12 |
<link href="css/prettify.css" rel="stylesheet"> |
| 13 |
<script src="js/prettify.js"></script> |
| 14 |
<script src="js/docs.js"></script> |
| 15 |
|
| 16 |
|
| 17 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 18 |
<script src="../js/jquery.tablesorter.js"></script> |
| 19 |
<script src="../js/widgets/widget-storage.js"></script> |
| 20 |
<script src="../js/widgets/widget-saveSort.js"></script> |
| 21 |
<script src="../js/parsers/parser-ignore-articles.js"></script> |
| 22 |
|
| 23 |
<script id="js">$(function() { |
| 24 |
|
| 25 |
// call the tablesorter plugin |
| 26 |
$("table").tablesorter({ |
| 27 |
theme: 'blue', |
| 28 |
|
| 29 |
// use save sort widget |
| 30 |
widgets: ["saveSort", "zebra"], |
| 31 |
widgetOptions: { |
| 32 |
// enable/disable saveSort dynamically |
| 33 |
saveSort: true |
| 34 |
} |
| 35 |
|
| 36 |
}); |
| 37 |
|
| 38 |
$('button').click(function() { |
| 39 |
$('table') |
| 40 |
.trigger('saveSortReset') // clear saved sort |
| 41 |
.trigger("sortReset"); // reset current table sort |
| 42 |
return false; |
| 43 |
}); |
| 44 |
|
| 45 |
});</script> |
| 46 |
</head> |
| 47 |
<body> |
| 48 |
<div id="banner"> |
| 49 |
<h1>table<em>sorter</em></h1> |
| 50 |
<h2>Save Sort Widget</h2> |
| 51 |
<h3>Flexible client-side table sorting</h3> |
| 52 |
<a href="index.html">Back to documentation</a> |
| 53 |
</div> |
| 54 |
<div id="main"> |
| 55 |
|
| 56 |
<p class="tip"> |
| 57 |
<em>NOTE!</em> |
| 58 |
</p> |
| 59 |
<ul> |
| 60 |
<li>As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.</li> |
| 61 |
<li>Sort one or more columns, then reload the page to see that this widget remembers the last table sort.</li> |
| 62 |
<li>Sort saving requires the new "$.tablesorter.storage()" function included with the "jquery.tablesorter.widgets.js" file (v2.1).</li> |
| 63 |
<li>Because this widget uses jQuery's <code>parseJson()</code> function, it requires jQuery version 1.4.1+.</li> |
| 64 |
<li>Added a <code>saveSortReset</code> method which only clears the stored information (v2.7.11).</li> |
| 65 |
</ul> |
| 66 |
|
| 67 |
<h1>Demo</h1> |
| 68 |
<div id="demo"><button type="button">Reset Sort</button> |
| 69 |
<br> |
| 70 |
<table class="tablesorter"> |
| 71 |
<thead> |
| 72 |
<tr> |
| 73 |
<th>Account #</th> |
| 74 |
<th>First Name</th> |
| 75 |
<th>Last Name</th> |
| 76 |
<th>Age</th> |
| 77 |
<th>Total</th> |
| 78 |
<th>Discount</th> |
| 79 |
<th>Diff</th> |
| 80 |
</tr> |
| 81 |
</thead> |
| 82 |
<tbody> |
| 83 |
<tr> |
| 84 |
<td>A43</td> |
| 85 |
<td>Peter</td> |
| 86 |
<td>Parker</td> |
| 87 |
<td>28</td> |
| 88 |
<td>9.99</td> |
| 89 |
<td>20.3%</td> |
| 90 |
<td>+3</td> |
| 91 |
</tr> |
| 92 |
<tr> |
| 93 |
<td>A255</td> |
| 94 |
<td>John</td> |
| 95 |
<td>Hood</td> |
| 96 |
<td>33</td> |
| 97 |
<td>19.99</td> |
| 98 |
<td>25.1%</td> |
| 99 |
<td>-7</td> |
| 100 |
</tr> |
| 101 |
<tr> |
| 102 |
<td>A33</td> |
| 103 |
<td>Clark</td> |
| 104 |
<td>Kent</td> |
| 105 |
<td>18</td> |
| 106 |
<td>15.89</td> |
| 107 |
<td>44.2%</td> |
| 108 |
<td>-15</td> |
| 109 |
</tr> |
| 110 |
<tr> |
| 111 |
<td>A1</td> |
| 112 |
<td>Bruce</td> |
| 113 |
<td>Almighty</td> |
| 114 |
<td>45</td> |
| 115 |
<td>153.19</td> |
| 116 |
<td>44%</td> |
| 117 |
<td>+19</td> |
| 118 |
</tr> |
| 119 |
<tr> |
| 120 |
<td>A102</td> |
| 121 |
<td>Bruce</td> |
| 122 |
<td>Evans</td> |
| 123 |
<td>56</td> |
| 124 |
<td>153.19</td> |
| 125 |
<td>23%</td> |
| 126 |
<td>+9</td> |
| 127 |
</tr> |
| 128 |
</tbody> |
| 129 |
</table> |
| 130 |
|
| 131 |
|
| 132 |
<table> |
| 133 |
<thead> |
| 134 |
<tr> |
| 135 |
<th>Rank</th> |
| 136 |
<th>Rating</th> |
| 137 |
<th class="sorter-ignoreArticles">Title</th> |
| 138 |
<th>Votes</th> |
| 139 |
</tr> |
| 140 |
</thead> |
| 141 |
<tbody> |
| 142 |
<tr> |
| 143 |
<td>1.</td> |
| 144 |
<td>9.2</td> |
| 145 |
<td><a href="http://www.imdb.com/title/tt0111161/">The Shawshank Redemption</a> (1994)</td> |
| 146 |
<td>734,327</td> |
| 147 |
</tr> |
| 148 |
<tr> |
| 149 |
<td>2.</td> |
| 150 |
<td>9.2</td> |
| 151 |
<td><a href="http://www.imdb.com/title/tt0068646/">The Godfather</a> (1972)</td> |
| 152 |
<td>548,857</td> |
| 153 |
</tr> |
| 154 |
<tr> |
| 155 |
<td>3.</td> |
| 156 |
<td>9.0</td> |
| 157 |
<td><a href="http://www.imdb.com/title/tt0071562/">The Godfather: Part II</a> (1974)</td> |
| 158 |
<td>346,072</td> |
| 159 |
</tr> |
| 160 |
<tr> |
| 161 |
<td>4.</td> |
| 162 |
<td>8.9</td> |
| 163 |
<td><a href="http://www.imdb.com/title/tt0110912/">Pulp Fiction</a> (1994)</td> |
| 164 |
<td>577,426</td> |
| 165 |
</tr> |
| 166 |
<tr> |
| 167 |
<td>5.</td> |
| 168 |
<td>8.9</td> |
| 169 |
<td><a href="http://www.imdb.com/title/tt0060196/">The Good, the Bad and the Ugly</a> (1966)</td> |
| 170 |
<td>229,564</td> |
| 171 |
</tr> |
| 172 |
</tbody> |
| 173 |
</table></div> |
| 174 |
|
| 175 |
<h1>Page Header</h1> |
| 176 |
<div> |
| 177 |
<pre class="prettyprint lang-html"> |
| 178 |
<link rel="stylesheet" href="css/blue/style.css"> |
| 179 |
<script src="js/jquery-latest.min.js"></script> |
| 180 |
<script src="js/jquery.tablesorter.min.js"></script> |
| 181 |
<script src="js/jquery.tablesorter.widgets.min.js"></script></pre> |
| 182 |
</div> |
| 183 |
<h1>Javascript</h1> |
| 184 |
<div id="javascript"> |
| 185 |
<pre class="prettyprint lang-javascript"></pre> |
| 186 |
</div> |
| 187 |
<h1>HTML</h1> |
| 188 |
<div id="html"> |
| 189 |
<pre class="prettyprint lang-html"></pre> |
| 190 |
</div> |
| 191 |
|
| 192 |
<div class="next-up"> |
| 193 |
<hr /> |
| 194 |
Next up: <a href="example-widget-sticky-header.html">Applying the sticky header widget ››</a> |
| 195 |
</div> |
| 196 |
|
| 197 |
</div> |
| 198 |
|
| 199 |
</body> |
| 200 |
</html> |