mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Add semantic version sorting demo. Fixes #395.
This commit is contained in:
parent
0167f895d7
commit
66ec824691
125
docs/example-option-textsorter-semver.html
Normal file
125
docs/example-option-textsorter-semver.html
Normal file
@ -0,0 +1,125 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>jQuery plugin: Tablesorter 2.0 - Semver Sorting</title>
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.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>
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<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>
|
@ -401,6 +401,7 @@
|
||||
<li><a href="example-parsers-feet-inch-fraction.html">Feet-inch-fraction parser</a> (<span class="version">v2.8</span>).</li>
|
||||
<li><a href="example-parsers-ip-address.html">IPv6 address parser</a> (<span class="version">v2.12</span>).</li>
|
||||
<li><a href="example-parsers-file-type.html">File type parser</a> (<span class="version">v2.13</span>).</li>
|
||||
<li><a href="example-option-textsorter-semver.html">Semantic Versioning (Semver) sorting</a> (<span class="version">v2.14.3</span>).</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
@ -1372,7 +1373,7 @@ $(function(){
|
||||
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="example-option-custom-sort.html">Example</a></td>
|
||||
<td>Ex:<a href="example-option-custom-sort.html">1</a> <a href="example-option-textsorter-semver.html">2</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="usnumberformat">
|
||||
|
1026
js/extras/semver-mod.js
Normal file
1026
js/extras/semver-mod.js
Normal file
File diff suppressed because it is too large
Load Diff
1011
js/extras/semver.js
Normal file
1011
js/extras/semver.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user