mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-12-05 05:04:20 +00:00
126 lines
4.0 KiB
HTML
126 lines
4.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>jQuery tablesorter 2.0 - Semver Sorting</title>
|
|
|
|
<!-- jQuery -->
|
|
<script src="js/jquery-latest.min.js"></script>
|
|
|
|
<!-- Demo stuff -->
|
|
<link rel="stylesheet" href="css/jq.css">
|
|
<link href="css/prettify.css" rel="stylesheet">
|
|
<script src="js/prettify.js"></script>
|
|
<script src="js/docs.js"></script>
|
|
|
|
<!-- Tablesorter: required -->
|
|
<link rel="stylesheet" href="../css/theme.blue.css">
|
|
<script src="../js/jquery.tablesorter.js"></script>
|
|
<script src="../js/extras/semver-mod.js"></script>
|
|
|
|
<style id="css">td.red { color: red; }</style>
|
|
|
|
<script id="js">$(function() {
|
|
|
|
// Set up empty table with second and first columns pre-sorted
|
|
$("table").tablesorter({
|
|
theme : 'blue',
|
|
// sortList: [[1,0]],
|
|
textSorter : {
|
|
1 : function(a,b) {
|
|
if (a === b) { return 0; }
|
|
if (window.semver && semver.valid(a) !== null && semver.valid(b) !== null) {
|
|
// valid version numbers, use semver.gt() method (greater than)
|
|
return semver.gt(a, b) ? 1 : -1;
|
|
} else {
|
|
// invalid version number or semver not included -> basic text sort
|
|
return a > b ? 1 : (a < b ? -1 : 0);
|
|
}
|
|
}
|
|
},
|
|
// extra code to highlight invalid semver numbers
|
|
initialized : function(table) {
|
|
var $cell,
|
|
c = table.config,
|
|
column = 1; // search second column (zero-based index)
|
|
if (window.semver) {
|
|
c.$tbodies.each(function(tbindex, tb) {
|
|
$(tb).children('tr').each(function(rowindex, tr) {
|
|
$cell = $(tr).children().eq(column);
|
|
if (semver.valid( $.trim( $cell.text() ) ) === null) {
|
|
// make invalid semver numbers obvious
|
|
$cell.addClass('red').append(' (invalid)');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
});</script>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="banner">
|
|
<h1>table<em>sorter</em></h1>
|
|
<h2>Semver Sorting</h2>
|
|
<h3>Flexible client-side table sorting</h3>
|
|
<a href="index.html">Back to documentation</a>
|
|
</div>
|
|
|
|
<div id="main">
|
|
|
|
<p class="tip">
|
|
<em>NOTE!</em>
|
|
</p>
|
|
<ul>
|
|
<li>This method does not use a parser nor a widget, it uses <code>semver.js</code> to allow the sorting of <a href="http://semver.org/">semantic version numbers</a>.</li>
|
|
<li>But this method requires a slightly modified version of <a href="https://github.com/isaacs/node-semver">semver.js for node</a>. All modifications are signified within the file to ease updating.</li>
|
|
<li>The modified semver.js (<a href="../js/extras/semver-mod.js">semver-mod.js</a>) is contained in the new "extras" subfolder. Please include it if you need this specific type of sort.</li>
|
|
<li>Invalid version numbers be sorted using a basic text sort, so they will be grouped with their similar version numbers, but not sorted properly; this demo has some extra code to highlight invalid version numbers.</li>
|
|
<li>In this demo, when the semver 2.0.0 compliant version column is sorted, the order column will be in sequential order.</li>
|
|
<li>Semver example order, from semver.org:<br>1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0</li>
|
|
<!-- http://jsfiddle.net/Mottie/abkNM/1626/ -->
|
|
</ul>
|
|
|
|
<h1>Demo</h1>
|
|
<div id="demo"><table class="tablesorter">
|
|
<thead>
|
|
<tr>
|
|
<th>Order</th>
|
|
<th>SemVer 2.0.0 compliant versioning</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td>6</td><td>1.0.0-beta.2</td></tr>
|
|
<tr><td>8</td><td>1.0.0-rc.1</td></tr>
|
|
<tr><td>2</td><td>1.0.0-alpha.1</td></tr>
|
|
<tr><td>1</td><td>1.0.0-alpha</td></tr>
|
|
<tr><td>10</td><td>1.0.0</td></tr>
|
|
<tr><td>4</td><td>1.0.0-alpha.beta</td></tr>
|
|
<tr><td>3</td><td>1.0.0-alpha.2</td></tr>
|
|
<tr><td>7</td><td>1.0.0-beta.11</td></tr>
|
|
<tr><td>9</td><td>1.0.0-rc.2</td></tr>
|
|
<tr><td>5</td><td>1.0.0-beta</td></tr>
|
|
<tr><td>11</td><td>1.0.0beta</td></tr>
|
|
</tbody>
|
|
</table></div>
|
|
|
|
<h1>Javascript</h1>
|
|
<div id="javascript">
|
|
<pre class="prettyprint lang-javascript"></pre>
|
|
</div>
|
|
<h1>CSS</h1>
|
|
<div id="css">
|
|
<pre class="prettyprint lang-css"></pre>
|
|
</div>
|
|
<h1>HTML</h1>
|
|
<div id="html">
|
|
<pre class="prettyprint lang-html"></pre>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|