| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Update headers & table body (updateAll)</title> |
| 6 |
|
| 7 |
|
| 8 |
<script src="js/jquery-latest.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 |
|
| 20 |
<script id="js">$(function() { |
| 21 |
|
| 22 |
// Set up empty table with second and first columns pre-sorted |
| 23 |
$("table").tablesorter({ theme : 'blue', sortList: [[2,0]] }); |
| 24 |
|
| 25 |
|
| 26 |
var indx = 0; |
| 27 |
$("#update").on('click', function() { |
| 28 |
|
| 29 |
// prevent link from removing all data from the column |
| 30 |
if (indx++ < 2) { |
| 31 |
|
| 32 |
// append new html to thead & tbody |
| 33 |
$("table thead th:eq(2)").html("Age"); |
| 34 |
$("table tbody").find('td:nth-child(3)').html(function(i,h) { |
| 35 |
return h.substring(1); // remove x & y prefix |
| 36 |
}); |
| 37 |
|
| 38 |
var resort = true, // re-apply the current sort |
| 39 |
callback = function() { |
| 40 |
// do something after the updateAll method has completed |
| 41 |
}; |
| 42 |
|
| 43 |
// let the plugin know that we made a update, then the plugin will |
| 44 |
// automatically sort the table based on the header settings |
| 45 |
$("table").trigger("updateAll", [ resort, callback ]); |
| 46 |
|
| 47 |
} |
| 48 |
return false; |
| 49 |
}); |
| 50 |
|
| 51 |
});</script> |
| 52 |
</head> |
| 53 |
<body> |
| 54 |
|
| 55 |
<div id="banner"> |
| 56 |
<h1>table<em>sorter</em></h1> |
| 57 |
<h2>Update headers & table body (updateAll)</h2> |
| 58 |
<h3>Flexible client-side table sorting</h3> |
| 59 |
<a href="index.html">Back to documentation</a> |
| 60 |
</div> |
| 61 |
|
| 62 |
<div id="main"> |
| 63 |
|
| 64 |
<p class="tip"> |
| 65 |
<em>NOTE!</em> |
| 66 |
</p> |
| 67 |
<ul> |
| 68 |
<li>This demo uses the <code>updateAll</code> method (<span class="version">v2.8</span>).</li> |
| 69 |
<li>This method allows you to update the cache with data from both the <code>thead</code> and <code>tbody</code> of the table.</li> |
| 70 |
<li>The <code>update</code> method only updates the cache from the <code>tbody</code>.</li> |
| 71 |
</ul> |
| 72 |
|
| 73 |
<h1>Demo</h1> |
| 74 |
<div id="demo"><table class="tablesorter"> |
| 75 |
<thead> |
| 76 |
<tr> |
| 77 |
<th>First Name</th> |
| 78 |
<th>Last Name</th> |
| 79 |
<th>Value</th> |
| 80 |
<th>Total</th> |
| 81 |
<th>Discount</th> |
| 82 |
<th>Date</th> |
| 83 |
</tr> |
| 84 |
</thead> |
| 85 |
<tbody> |
| 86 |
<tr><td>Peter</td><td>Parker</td><td>x28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr> |
| 87 |
<tr><td>John</td><td>Hood</td><td>y33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr> |
| 88 |
<tr><td>Clark</td><td>Kent</td><td>y18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr> |
| 89 |
<tr><td>Bruce</td><td>Almighty</td><td>x45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr> |
| 90 |
</tbody> |
| 91 |
</table> |
| 92 |
|
| 93 |
<a href="#" id="update">Modify the entire value column</a> |
| 94 |
</div> |
| 95 |
|
| 96 |
<h1>Javascript</h1> |
| 97 |
<div id="javascript"> |
| 98 |
<pre class="prettyprint lang-javascript"></pre> |
| 99 |
</div> |
| 100 |
<h1>HTML</h1> |
| 101 |
<div id="html"> |
| 102 |
<pre class="prettyprint lang-html"></pre> |
| 103 |
|
| 104 |
<div class="next-up"> |
| 105 |
<hr /> |
| 106 |
Next up: <a href="example-update-cell.html">Update the table after cell content has changed ››</a> |
| 107 |
</div> |
| 108 |
|
| 109 |
</div> |
| 110 |
|
| 111 |
</div> |
| 112 |
|
| 113 |
</body> |
| 114 |
</html> |