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 - Writing custom parsers</title>
|
|
|
|
|
|
|
|
<!-- jQuery -->
|
2011-07-17 15:01:18 +00:00
|
|
|
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/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">
|
|
|
|
<script src="js/chili/jquery.chili-2.2.js"></script>
|
|
|
|
<script src="js/chili/recipes.js"></script>
|
|
|
|
<script src="js/docs.js"></script>
|
2011-06-22 23:19:27 +00:00
|
|
|
|
|
|
|
<!-- Tablesorter: required -->
|
2011-07-17 15:01:18 +00:00
|
|
|
<link rel="stylesheet" href="../css/blue/style.css">
|
|
|
|
<script src="../js/jquery.tablesorter.js"></script>
|
|
|
|
<script src="../addons/pager/jquery.tablesorter.pager.js"></script>
|
|
|
|
|
|
|
|
<script id="js">// add parser through the tablesorter addParser method
|
2011-06-22 23:19:27 +00:00
|
|
|
$.tablesorter.addParser({
|
|
|
|
// set a unique id
|
|
|
|
id: 'grades',
|
|
|
|
is: function(s) {
|
|
|
|
// return false so this parser is not auto detected
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
format: function(s) {
|
|
|
|
// format your data for normalization
|
2011-07-17 15:01:18 +00:00
|
|
|
return s.toLowerCase()
|
|
|
|
.replace(/good/,2)
|
|
|
|
.replace(/medium/,1)
|
|
|
|
.replace(/bad/,0);
|
2011-06-22 23:19:27 +00:00
|
|
|
},
|
|
|
|
// set type, either numeric or text
|
|
|
|
type: 'numeric'
|
|
|
|
});
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
$("table").tablesorter({
|
2011-08-04 06:24:26 +00:00
|
|
|
// "sorter-grades" added as a class name in the HTML (new in v2.0.11)
|
|
|
|
// or un-comment out the option below
|
|
|
|
// headers: { 6: { sorter: 'grades' } }
|
2011-06-22 23:19:27 +00:00
|
|
|
});
|
2011-07-17 15:01:18 +00:00
|
|
|
|
2011-06-22 23:19:27 +00:00
|
|
|
});</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-07-17 15:01:18 +00:00
|
|
|
|
2011-06-22 23:19:27 +00:00
|
|
|
<div id="banner">
|
|
|
|
<h1>table<em>sorter</em></h1>
|
|
|
|
<h2>Writing custom parsers</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-09-08 16:28:10 +00:00
|
|
|
|
|
|
|
<p class="tip">
|
|
|
|
<em>NOTE!</em> Assigning the parser using a class name was added in version 2.0.11 (it is not part of the original plugin).
|
|
|
|
</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>
|
2011-08-04 06:24:26 +00:00
|
|
|
<th class="sorter-text">Name</th>
|
2011-07-17 15:01:18 +00:00
|
|
|
<th>Major</th>
|
|
|
|
<th>Gender</th>
|
|
|
|
<th>English</th>
|
|
|
|
<th>Japanese</th>
|
|
|
|
<th>Calculus</th>
|
2011-08-04 06:24:26 +00:00
|
|
|
<th class="sorter-grades">Overall grades</th> <!-- set the column parser using a class name -->
|
2011-07-17 15:01:18 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>Student01</td>
|
|
|
|
<td>Languages</td>
|
|
|
|
<td>male</td>
|
|
|
|
<td>80</td>
|
|
|
|
<td>70</td>
|
|
|
|
<td>75</td>
|
|
|
|
<td>bad</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Student02</td>
|
|
|
|
<td>Mathematics</td>
|
|
|
|
<td>male</td>
|
|
|
|
<td>90</td>
|
|
|
|
<td>88</td>
|
|
|
|
<td>100</td>
|
|
|
|
<td>good</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Student03</td>
|
|
|
|
<td>Languages</td>
|
|
|
|
<td>female</td>
|
|
|
|
<td>85</td>
|
|
|
|
<td>95</td>
|
|
|
|
<td>80</td>
|
|
|
|
<td>medium</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table></div>
|
2011-06-22 23:19:27 +00:00
|
|
|
|
|
|
|
<h1>Javascript</h1>
|
|
|
|
<div id="javascript">
|
2011-07-17 15:01:18 +00:00
|
|
|
<pre class="js"></pre>
|
2011-06-22 23:19:27 +00:00
|
|
|
</div>
|
|
|
|
<h1>HTML</h1>
|
|
|
|
<div id="html">
|
|
|
|
<pre class="html"></pre>
|
|
|
|
</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-option-text-extraction.html">Dealing with markup inside cells (textExtraction function) ››</a>
|
2011-07-17 15:01:18 +00:00
|
|
|
</div>
|
|
|
|
|
2011-06-22 23:19:27 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|