tablesorter/docs/example-option-text-extraction.html

142 lines
3.7 KiB
HTML
Raw Normal View History

2011-07-17 15:01:18 +00:00
<!DOCTYPE html>
<html>
2011-06-22 23:19:27 +00:00
<head>
2011-07-17 15:01:18 +00:00
<meta charset="utf-8">
2011-06-22 23:19:27 +00:00
<title>jQuery plugin: Tablesorter 2.0 - Dealing with markup inside cells</title>
<!-- jQuery -->
2012-03-03 01:38:02 +00:00
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
2011-06-22 23:19:27 +00:00
<!-- Demo stuff -->
2011-07-17 15:01:18 +00:00
<link rel="stylesheet" href="css/jq.css">
<link href="css/prettify.css" rel="stylesheet">
<script src="js/prettify.js"></script>
2011-07-17 15:01:18 +00:00
<script src="js/docs.js"></script>
2011-06-22 23:19:27 +00:00
<!-- Tablesorter: required -->
2012-09-27 19:57:19 +00:00
<link rel="stylesheet" href="../css/theme.blue.css">
2011-07-17 15:01:18 +00:00
<script src="../js/jquery.tablesorter.js"></script>
2011-06-22 23:19:27 +00:00
2011-07-17 15:01:18 +00:00
<script id="js">$(function() {
2011-06-22 23:19:27 +00:00
// call the tablesorter plugin
$("table").tablesorter({
2012-09-27 19:57:19 +00:00
theme : 'blue',
2011-08-19 06:24:29 +00:00
/*
// define an overall custom text extraction function
2012-03-11 14:45:10 +00:00
textExtraction: function(node, table, cellIndex) {
2011-07-17 15:01:18 +00:00
return $(node).text();
2011-06-22 23:19:27 +00:00
}
2011-08-19 06:24:29 +00:00
*/
// Define a custom text extraction function for each column
// In this example, textExtraction 1-5 functions don't really need to
// be defined, since they can also be obtained using `$(node).text()`
2011-08-19 06:24:29 +00:00
textExtraction: {
2012-03-11 14:45:10 +00:00
0: function(node, table, cellIndex){ return $(node).find("strong").text(); },
1: function(node, table, cellIndex){ return $(node).find("div").text(); },
2: function(node, table, cellIndex){ return $(node).find("span").text(); },
3: function(node, table, cellIndex){ return $(node).find("em").text(); },
4: function(node, table, cellIndex){ return $(node).find("a").text(); },
5: function(node, table, cellIndex){ return $(node).find("u").text(); }
2011-08-19 06:24:29 +00:00
}
2011-07-17 15:01:18 +00:00
2011-06-22 23:19:27 +00:00
});
2011-07-17 15:01:18 +00:00
});</script>
2011-06-22 23:19:27 +00:00
</head>
<body>
2011-07-17 15:01:18 +00:00
2011-06-22 23:19:27 +00:00
<div id="banner">
2011-08-19 06:24:29 +00:00
<h1>table<strong>sorter</strong></h1>
2011-06-22 23:19:27 +00:00
<h2>Dealing with markup inside cells</h2>
<h3>Flexible client-side table sorting</h3>
<a href="index.html">Back to documentation</a>
</div>
2011-07-17 15:01:18 +00:00
2011-06-22 23:19:27 +00:00
<div id="main">
2011-08-19 06:24:29 +00:00
<p class="tip">
2011-09-08 16:28:10 +00:00
<em>NOTE!</em>
<ul>
<li>The textExtraction function setting for each column was added in version 2.0.12 (not part of the original plugin).</li>
<li>The "First Name" column is sorting by the contents of the &lt;strong&gt; tag (in red).</li>
<li>Added "table" and "cellIndex" variables to the textExtraction function (v2.1.2).</li>
2011-09-08 16:28:10 +00:00
</ul>
2011-08-19 06:24:29 +00:00
</p>
2011-06-22 23:19:27 +00:00
<h1>Demo</h1>
2011-07-17 15:01:18 +00:00
<div id="demo"><table class="tablesorter">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Total</th>
<th>Discount</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
2011-08-19 06:24:29 +00:00
<td>Mr. <strong>Peter</strong></td>
<td><div>Parker</div></td>
<td><span>28</span></td>
<td><em>$9.99</em></td>
<td><a href="#">20%</a></td>
<td><u>Jul 6, 2006 8:14 AM</u></td>
2011-07-17 15:01:18 +00:00
</tr>
<tr>
2011-08-19 06:24:29 +00:00
<td>Dr. <strong>John</strong></td>
<td><div>Hood</div></td>
<td><span>33</span></td>
<td><em>$19.99</em></td>
<td><a href="#">25%</a></td>
<td><u>Dec 10, 2002 5:14 AM</u></td>
2011-07-17 15:01:18 +00:00
</tr>
<tr>
2011-08-19 06:24:29 +00:00
<td>Rep <strong>Clark</strong></td>
<td><div>Kent</div></td>
<td><span>18</span></td>
<td><em>$15.89</em></td>
<td><a href="#">44%</a></td>
<td><u>Jan 12, 2003 11:14 AM</u></td>
2011-07-17 15:01:18 +00:00
</tr>
<tr>
2011-08-19 06:24:29 +00:00
<td>Rev <strong>Bruce</strong></td>
<td><div>Almighty</div></td>
<td><span>45</span></td>
<td><em>$153.19</em></td>
<td><a href="#">44%</a></td>
<td><u>Jan 18, 2001 9:12 AM</u></td>
2011-07-17 15:01:18 +00:00
</tr>
<tr>
2011-08-19 06:24:29 +00:00
<td>Capt <strong>Bruce</strong></td>
<td><div>Evans</div></td>
<td><span>22</span></td>
<td><em>$13.19</em></td>
<td><a href="#">11%</a></td>
<td><u>Jan 18, 2007 9:12 AM</u></td>
2011-07-17 15:01:18 +00:00
</tr>
</tbody>
</table></div>
2011-06-22 23:19:27 +00:00
<h1>Javascript</h1>
<div id="javascript">
<pre class="prettyprint lang-javascript"></pre>
2011-06-22 23:19:27 +00:00
</div>
<h1>HTML</h1>
<div id="html">
<pre class="prettyprint lang-html"></pre>
2011-06-22 23:19:27 +00:00
</div>
2011-07-17 15:01:18 +00:00
<div class="next-up">
<hr />
2011-10-26 06:50:02 +00:00
Next up: <a href="example-apply-widget.html">Applying widgets &rsaquo;&rsaquo;</a>
2011-07-17 15:01:18 +00:00
</div>
2011-06-22 23:19:27 +00:00
</div>
</body>
</html>