tablesorter/docs/example-parsers.html

155 lines
3.2 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 - Writing custom parsers</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>
<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',
2013-01-29 22:42:23 +00:00
is: function(s) {
2011-06-22 23:19:27 +00:00
// return false so this parser is not auto detected
2013-01-29 22:42:23 +00:00
return false;
},
2012-03-07 18:06:35 +00:00
format: function(s, table, cell, cellIndex) {
2011-06-22 23:19:27 +00:00
// 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({
2012-09-27 19:57:19 +00:00
theme: 'blue'
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
2012-09-27 19:57:19 +00:00
// ,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>
2012-09-27 19:57:19 +00:00
<td>medium</td>
2011-07-17 15:01:18 +00:00
</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>
2012-09-27 19:57:19 +00:00
<td>good</td>
</tr>
<tr>
<td>Student04</td>
<td>Languages</td>
<td>male</td>
<td>20</td>
<td>50</td>
<td>65</td>
<td>bad</td>
</tr>
<tr>
<td>Student05</td>
<td>Mathematics</td>
<td>female</td>
<td>70</td>
<td>78</td>
<td>70</td>
2011-07-17 15:01:18 +00:00
<td>medium</td>
</tr>
2012-09-27 19:57:19 +00:00
<tr>
<td>Student06</td>
<td>Mathematics</td>
<td>male</td>
<td>44</td>
<td>65</td>
<td>60</td>
<td>bad</td>
</tr>
2011-07-17 15:01:18 +00:00
</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 />
2012-03-07 18:06:35 +00:00
Next up: <a href="example-parsers-advanced.html">Writing custom parsers, advanced &rsaquo;&rsaquo;</a>
2011-07-17 15:01:18 +00:00
</div>
2011-06-22 23:19:27 +00:00
</div>
</body>
</html>