Debian Codegraph @

docs/example-option-textsorter-semver.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Semver Sorting</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link rel="stylesheet" href="css/jq.css">
12 <link href="css/prettify.css" rel="stylesheet">
13 <script src="js/prettify.js"></script>
14 <script src="js/docs.js"></script>
15
16 <!-- Tablesorter: required -->
17 <link rel="stylesheet" href="../css/theme.blue.css">
18 <script src="../js/jquery.tablesorter.js"></script>
19 <script src="../js/extras/semver-mod.js"></script>
20
21 <style id="css">td.red { color: red; }</style>
22
23 <script id="js">$(function() {
24
25 // Set up empty table with second and first columns pre-sorted
26 $("table").tablesorter({
27 theme : 'blue',
28 // sortList: [[1,0]],
29 textSorter : {
30 1 : function(a,b) {
31 if (a === b) { return 0; }
32 if (window.semver && semver.valid(a) !== null && semver.valid(b) !== null) {
33 // valid version numbers, use semver.gt() method (greater than)
34 return semver.gt(a, b) ? 1 : -1;
35 } else {
36 // invalid version number or semver not included -> basic text sort
37 return a > b ? 1 : (a < b ? -1 : 0);
38 }
39 }
40 },
41 // extra code to highlight invalid semver numbers
42 initialized : function(table) {
43 var $cell,
44 c = table.config,
45 column = 1; // search second column (zero-based index)
46 if (window.semver) {
47 c.$tbodies.each(function(tbindex, tb) {
48 $(tb).children('tr').each(function(rowindex, tr) {
49 $cell = $(tr).children().eq(column);
50 if (semver.valid( $.trim( $cell.text() ) ) === null) {
51 // make invalid semver numbers obvious
52 $cell.addClass('red').append(' (invalid)');
53 }
54 });
55 });
56 }
57 }
58 });
59
60 });</script>
61 </head>
62 <body>
63
64 <div id="banner">
65 <h1>table<em>sorter</em></h1>
66 <h2>Semver Sorting</h2>
67 <h3>Flexible client-side table sorting</h3>
68 <a href="index.html">Back to documentation</a>
69 </div>
70
71 <div id="main">
72
73 <p class="tip">
74 <em>NOTE!</em>
75 </p>
76 <ul>
77 <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>
78 <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>
79 <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>
80 <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>
81 <li>In this demo, when the semver 2.0.0 compliant version column is sorted, the order column will be in sequential order.</li>
82 <li>Semver example order, from semver.org:<br>1.0.0-alpha &lt; 1.0.0-alpha.1 &lt; 1.0.0-alpha.beta &lt; 1.0.0-beta &lt; 1.0.0-beta.2 &lt; 1.0.0-beta.11 &lt; 1.0.0-rc.1 &lt; 1.0.0</li>
83 <!-- http://jsfiddle.net/Mottie/abkNM/1626/ -->
84 </ul>
85
86 <h1>Demo</h1>
87 <div id="demo"><table class="tablesorter">
88 <thead>
89 <tr>
90 <th>Order</th>
91 <th>SemVer 2.0.0 compliant versioning</th>
92 </tr>
93 </thead>
94 <tbody>
95 <tr><td>6</td><td>1.0.0-beta.2</td></tr>
96 <tr><td>8</td><td>1.0.0-rc.1</td></tr>
97 <tr><td>2</td><td>1.0.0-alpha.1</td></tr>
98 <tr><td>1</td><td>1.0.0-alpha</td></tr>
99 <tr><td>10</td><td>1.0.0</td></tr>
100 <tr><td>4</td><td>1.0.0-alpha.beta</td></tr>
101 <tr><td>3</td><td>1.0.0-alpha.2</td></tr>
102 <tr><td>7</td><td>1.0.0-beta.11</td></tr>
103 <tr><td>9</td><td>1.0.0-rc.2</td></tr>
104 <tr><td>5</td><td>1.0.0-beta</td></tr>
105 <tr><td>11</td><td>1.0.0beta</td></tr>
106 </tbody>
107 </table></div>
108
109 <h1>Javascript</h1>
110 <div id="javascript">
111 <pre class="prettyprint lang-javascript"></pre>
112 </div>
113 <h1>CSS</h1>
114 <div id="css">
115 <pre class="prettyprint lang-css"></pre>
116 </div>
117 <h1>HTML</h1>
118 <div id="html">
119 <pre class="prettyprint lang-html"></pre>
120 </div>
121
122 </div>
123
124 </body>
125 </html>