| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Dealing with markup inside cells</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 |
// call the tablesorter plugin |
| 23 |
$("table").tablesorter({ |
| 24 |
theme : 'blue', |
| 25 |
/* |
| 26 |
// define an overall custom text extraction function |
| 27 |
textExtraction: function(node, table, cellIndex) { |
| 28 |
return $(node).text(); |
| 29 |
} |
| 30 |
*/ |
| 31 |
|
| 32 |
// Define a custom text extraction function for each column |
| 33 |
// In this example, textExtraction 1-5 functions don't really need to |
| 34 |
// be defined, since they can also be obtained using `$(node).text()` |
| 35 |
textExtraction: { |
| 36 |
0: function(node, table, cellIndex) { return $(node).find("strong").text(); }, |
| 37 |
1: function(node, table, cellIndex) { return $(node).find("div").text(); }, |
| 38 |
2: function(node, table, cellIndex) { return $(node).find("span").text(); }, |
| 39 |
3: function(node, table, cellIndex) { return $(node).find("em").text(); }, |
| 40 |
4: function(node, table, cellIndex) { return $(node).find("a").text(); }, |
| 41 |
'.date' : function(node, table, cellIndex) { return $(node).find("u").text(); } |
| 42 |
} |
| 43 |
|
| 44 |
}); |
| 45 |
|
| 46 |
});</script> |
| 47 |
</head> |
| 48 |
<body> |
| 49 |
|
| 50 |
<div id="banner"> |
| 51 |
<h1>table<strong>sorter</strong></h1> |
| 52 |
<h2>Dealing with markup inside cells</h2> |
| 53 |
<h3>Flexible client-side table sorting</h3> |
| 54 |
<a href="index.html">Back to documentation</a> |
| 55 |
</div> |
| 56 |
|
| 57 |
<div id="main"> |
| 58 |
<p class="tip"> |
| 59 |
<em>NOTE!</em> |
| 60 |
</p> |
| 61 |
<ul> |
| 62 |
<li>In <span class="version updated">v2.17.0</span>, the <code>textExtraction</code> column can also be referenced by using a jQuery selector (e.g. class name or ID).</li> |
| 63 |
<li>The textExtraction function setting for each column was added in version 2.0.12 (not part of the original plugin).</li> |
| 64 |
<li>The "First Name" column is sorting by the contents of the <strong> tag (in red).</li> |
| 65 |
<li>Added "table" and "cellIndex" variables to the textExtraction function (v2.1.2).</li> |
| 66 |
</ul> |
| 67 |
|
| 68 |
<h1>Demo</h1> |
| 69 |
<div id="demo"><table class="tablesorter"> |
| 70 |
<thead> |
| 71 |
<tr> |
| 72 |
<th>First Name</th> |
| 73 |
<th>Last Name</th> |
| 74 |
<th>Age</th> |
| 75 |
<th>Total</th> |
| 76 |
<th>Discount</th> |
| 77 |
<th class="date">Date</th> |
| 78 |
</tr> |
| 79 |
</thead> |
| 80 |
<tbody> |
| 81 |
<tr> |
| 82 |
<td>Mr. <strong>Peter</strong></td> |
| 83 |
<td><div>Parker</div></td> |
| 84 |
<td><span>28</span></td> |
| 85 |
<td><em>$9.99</em></td> |
| 86 |
<td><a href="#">20%</a></td> |
| 87 |
<td><u>Jul 6, 2006 8:14 AM</u></td> |
| 88 |
</tr> |
| 89 |
<tr> |
| 90 |
<td>Dr. <strong>John</strong></td> |
| 91 |
<td><div>Hood</div></td> |
| 92 |
<td><span>33</span></td> |
| 93 |
<td><em>$19.99</em></td> |
| 94 |
<td><a href="#">25%</a></td> |
| 95 |
<td><u>Dec 10, 2002 5:14 AM</u></td> |
| 96 |
</tr> |
| 97 |
<tr> |
| 98 |
<td>Rep <strong>Clark</strong></td> |
| 99 |
<td><div>Kent</div></td> |
| 100 |
<td><span>18</span></td> |
| 101 |
<td><em>$15.89</em></td> |
| 102 |
<td><a href="#">44%</a></td> |
| 103 |
<td><u>Jan 12, 2003 11:14 AM</u></td> |
| 104 |
</tr> |
| 105 |
<tr> |
| 106 |
<td>Rev <strong>Bruce</strong></td> |
| 107 |
<td><div>Almighty</div></td> |
| 108 |
<td><span>45</span></td> |
| 109 |
<td><em>$153.19</em></td> |
| 110 |
<td><a href="#">44%</a></td> |
| 111 |
<td><u>Jan 18, 2001 9:12 AM</u></td> |
| 112 |
</tr> |
| 113 |
<tr> |
| 114 |
<td>Capt <strong>Bruce</strong></td> |
| 115 |
<td><div>Evans</div></td> |
| 116 |
<td><span>22</span></td> |
| 117 |
<td><em>$13.19</em></td> |
| 118 |
<td><a href="#">11%</a></td> |
| 119 |
<td><u>Jan 18, 2007 9:12 AM</u></td> |
| 120 |
</tr> |
| 121 |
</tbody> |
| 122 |
</table></div> |
| 123 |
|
| 124 |
<h1>Javascript</h1> |
| 125 |
<div id="javascript"> |
| 126 |
<pre class="prettyprint lang-javascript"></pre> |
| 127 |
</div> |
| 128 |
<h1>HTML</h1> |
| 129 |
<div id="html"> |
| 130 |
<pre class="prettyprint lang-html"></pre> |
| 131 |
</div> |
| 132 |
|
| 133 |
<div class="next-up"> |
| 134 |
<hr /> |
| 135 |
Next up: <a href="example-apply-widget.html">Applying widgets ››</a> |
| 136 |
</div> |
| 137 |
|
| 138 |
</div> |
| 139 |
|
| 140 |
</body> |
| 141 |
</html> |