| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Updating a table cell</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 |
<style> |
| 21 |
.discount { cursor: pointer; } |
| 22 |
</style> |
| 23 |
|
| 24 |
<script id="js">$(function() { |
| 25 |
|
| 26 |
$("table").tablesorter({ theme: 'blue', sortList: [[3,1],[0,0]] }); |
| 27 |
|
| 28 |
$("table tbody td.discount").click(function() { |
| 29 |
|
| 30 |
// randomize a number |
| 31 |
var resort = "", // resort variable set to anything BUT false (without quotes) will trigger the automatic resort |
| 32 |
discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' + ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2), |
| 33 |
callback = function(table) { /* do something */ }; |
| 34 |
$(this).text(discount); |
| 35 |
|
| 36 |
// set resort flag to false to prevent automatic resort |
| 37 |
// leave the resort flag as undefined, or with any other value, to automatically resort the table |
| 38 |
$("table").trigger("updateCell",[this, resort, callback]); |
| 39 |
|
| 40 |
return false; |
| 41 |
}); |
| 42 |
|
| 43 |
});</script> |
| 44 |
</head> |
| 45 |
<body> |
| 46 |
|
| 47 |
<div id="banner"> |
| 48 |
<h1>table<em>sorter</em></h1> |
| 49 |
<h2>Updating a table cell</h2> |
| 50 |
<h3>Flexible client-side table sorting</h3> |
| 51 |
<a href="index.html">Back to documentation</a> |
| 52 |
</div> |
| 53 |
|
| 54 |
<div id="main"> |
| 55 |
|
| 56 |
<p class="tip"> |
| 57 |
<em>NOTE!</em> |
| 58 |
</p> |
| 59 |
<ul> |
| 60 |
<li>Click on any value in the Total column to change it to a random amount.</li> |
| 61 |
<li>This option is part of the original plugin.</li> |
| 62 |
<li>Automatic resorting after "updateCell" is triggered was added in version 2.0.14.</li> |
| 63 |
</ul> |
| 64 |
|
| 65 |
<h1>Demo</h1> |
| 66 |
<div id="demo"><table class="tablesorter"> |
| 67 |
<thead> |
| 68 |
<tr> |
| 69 |
<th>First Name</th> |
| 70 |
<th>Last Name</th> |
| 71 |
<th>Age</th> |
| 72 |
<th>Total</th> |
| 73 |
<th>Discount</th> |
| 74 |
<th>Date</th> |
| 75 |
</tr> |
| 76 |
</thead> |
| 77 |
<tbody> |
| 78 |
<tr> |
| 79 |
<td>Peter</td> |
| 80 |
<td>Parker</td> |
| 81 |
<td>28</td> |
| 82 |
<td class="discount">$9.99</td> |
| 83 |
<td>20%</td> |
| 84 |
<td>Jul 6, 2006 8:14 AM</td> |
| 85 |
</tr> |
| 86 |
<tr> |
| 87 |
<td>John</td> |
| 88 |
<td>Hood</td> |
| 89 |
<td>33</td> |
| 90 |
<td class="discount">$19.99</td> |
| 91 |
<td>25%</td> |
| 92 |
<td>Dec 10, 2002 5:14 AM</td> |
| 93 |
</tr> |
| 94 |
<tr> |
| 95 |
<td>Clark</td> |
| 96 |
<td>Kent</td> |
| 97 |
<td>18</td> |
| 98 |
<td class="discount">$15.89</td> |
| 99 |
<td>44%</td> |
| 100 |
<td>Jan 12, 2003 11:14 AM</td> |
| 101 |
</tr> |
| 102 |
<tr> |
| 103 |
<td>Bruce</td> |
| 104 |
<td>Almighty</td> |
| 105 |
<td>45</td> |
| 106 |
<td class="discount">$153.19</td> |
| 107 |
<td>44%</td> |
| 108 |
<td>Jan 18, 2001 9:12 AM</td> |
| 109 |
</tr> |
| 110 |
<tr> |
| 111 |
<td>Bruce</td> |
| 112 |
<td>Evans</td> |
| 113 |
<td>22</td> |
| 114 |
<td class="discount">$13.19</td> |
| 115 |
<td>11%</td> |
| 116 |
<td>Jan 18, 2007 9:12 AM</td> |
| 117 |
</tr> |
| 118 |
</tbody> |
| 119 |
</table></div> |
| 120 |
|
| 121 |
<h1>Javascript</h1> |
| 122 |
<div id="javascript"> |
| 123 |
<pre class="prettyprint lang-javascript"></pre> |
| 124 |
</div> |
| 125 |
<h1>HTML</h1> |
| 126 |
<div id="html"> |
| 127 |
<pre class="prettyprint lang-html"></pre> |
| 128 |
</div> |
| 129 |
|
| 130 |
<div class="next-up"> |
| 131 |
<hr /> |
| 132 |
Next up: <a href="example-option-render-header.html">Modify how the header is rendered to allow for custom styling ››</a> |
| 133 |
</div> |
| 134 |
|
| 135 |
</div> |
| 136 |
|
| 137 |
</body> |
| 138 |
</html> |