| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Roman Numeral Parser</title> |
| 6 |
|
| 7 |
|
| 8 |
<script src="js/jquery-latest.min.js"></script> |
| 9 |
|
| 10 |
|
| 11 |
<link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css"> |
| 12 |
<script src="js/jquery-ui.min.js"></script> |
| 13 |
<link rel="stylesheet" href="css/jq.css"> |
| 14 |
<link href="css/prettify.css" rel="stylesheet"> |
| 15 |
<script src="js/prettify.js"></script> |
| 16 |
<script src="js/docs.js"></script> |
| 17 |
|
| 18 |
|
| 19 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 20 |
<script src="../js/jquery.tablesorter.js"></script> |
| 21 |
<script src="../js/jquery.tablesorter.widgets.js"></script> |
| 22 |
<script src="../js/parsers/parser-roman.js"></script> |
| 23 |
|
| 24 |
<style> |
| 25 |
th { width: 20%; } |
| 26 |
</style> |
| 27 |
|
| 28 |
<script id="js">$(function() { |
| 29 |
|
| 30 |
$("table").tablesorter({ |
| 31 |
theme: 'blue', |
| 32 |
widgets: ['zebra'], |
| 33 |
|
| 34 |
// roman numeral parser option |
| 35 |
// =========================== |
| 36 |
// column 0 & 1 are set to zero as placeholders |
| 37 |
// column 2: ignore last character (1) - for Roman "roman-ignore" numeral parser |
| 38 |
// column 3: ignore characters that match the set regex (beginning of the string to first space) |
| 39 |
roman_ignore: [ 0, 0, 1, /^(\w+\s)/ ] |
| 40 |
|
| 41 |
}); |
| 42 |
|
| 43 |
});</script> |
| 44 |
|
| 45 |
</head> |
| 46 |
<body> |
| 47 |
<div id="banner"> |
| 48 |
<h1>table<em>sorter</em></h1> |
| 49 |
<h2>Roman Numeral Parser</h2> |
| 50 |
<h3>Flexible client-side table sorting</h3> |
| 51 |
<a href="index.html">Back to documentation</a> |
| 52 |
</div> |
| 53 |
<div id="main"> |
| 54 |
|
| 55 |
<p></p> |
| 56 |
<br> |
| 57 |
|
| 58 |
<div id="root" class="accordion"> |
| 59 |
|
| 60 |
<h3><a href="#">Notes</a></h3> |
| 61 |
<div> |
| 62 |
<ul> |
| 63 |
<li>This parser (added <span class="version">v2.17.3</span>) will convert roman numerals into their decimal equivalent so the table column can be sorted correctly.</li> |
| 64 |
<li>There are actually 3 separate parsers included with this script. |
| 65 |
<ul> |
| 66 |
<li>They are very similar, but were written to cover different use cases.</li> |
| 67 |
<li> Refer to each in their separate sections below.</li> |
| 68 |
</ul> |
| 69 |
</li> |
| 70 |
<li>This demo includes the stored roman numeral values within the table cells, toggle the view using the button directly above the table.</li> |
| 71 |
</ul> |
| 72 |
</div> |
| 73 |
|
| 74 |
<h3><a href="#">"roman" parser</a></h3> |
| 75 |
<div> |
| 76 |
<ul> |
| 77 |
<li>This parser is optimized for columns that contain only roman numerals.</li> |
| 78 |
<li>In the demo below, this parser is used for the "Short" and "Long" columns.</li> |
| 79 |
<li>This parser has no option settings.</li> |
| 80 |
</ul> |
| 81 |
<pre class="prettyprint lang-js">$(function() { |
| 82 |
|
| 83 |
$("table").tablesorter({ |
| 84 |
theme: 'blue', |
| 85 |
widgets: ['zebra'], |
| 86 |
headers: { |
| 87 |
0 : { sorter: 'roman' }, |
| 88 |
1 : { sorter: 'roman' } |
| 89 |
} |
| 90 |
}); |
| 91 |
|
| 92 |
});</pre> |
| 93 |
|
| 94 |
</div> |
| 95 |
|
| 96 |
<h3><a href="#">"roman-ignore" parser</a></h3> |
| 97 |
<div> |
| 98 |
This parser is designed to use the <code>roman_ignore</code> option to either: |
| 99 |
|
| 100 |
<h4>Ignore The Last "X" Characters</h4> |
| 101 |
For content that contains a roman number followed by an alphabetical character, such as "Ia" or "IIb", this parser can be set to ignore the last character (spaces are trimmed automatically): |
| 102 |
<pre class="prettyprint lang-js">$(function() { |
| 103 |
|
| 104 |
$("table").tablesorter({ |
| 105 |
theme: 'blue', |
| 106 |
widgets: ['zebra'], |
| 107 |
headers: { |
| 108 |
2 : { sorter: 'roman-ignore' } |
| 109 |
}, |
| 110 |
// roman numeral parser option |
| 111 |
// ignore the last (1) character(s) in column 2 (zero-based index) |
| 112 |
// the two zeros in the array are just placeholders ( [ , , 1 ] works as well ) |
| 113 |
roman_ignore: [ 0, 0, 1 ] |
| 114 |
|
| 115 |
}); |
| 116 |
|
| 117 |
});</pre> |
| 118 |
|
| 119 |
<h4>Remove Non-Roman Numerals</h4> |
| 120 |
For cells that contain a bit more complex layout, you can define a regular expression to ignore (remove) certain parts of the content.<br> |
| 121 |
<br> |
| 122 |
The value obtained from the <code>roman_ignore</code> option array is <em>used within a javascript replace function</em>, so it can be either a <strong>regular expression</strong> or a <strong>string</strong>.<br> |
| 123 |
<br> |
| 124 |
In this example (see the "Ignore regex" column in the demo below), content at the beginning of the cell is set to be ignored. This should <em>leave</em> the roman numeral string to be parsed by this script (spaces are trimmed automatically). |
| 125 |
<pre class="prettyprint lang-js">$(function() { |
| 126 |
|
| 127 |
$("table").tablesorter({ |
| 128 |
theme: 'blue', |
| 129 |
widgets: ['zebra'], |
| 130 |
headers: { |
| 131 |
3 : { sorter: 'roman-ignore' } |
| 132 |
}, |
| 133 |
// roman numeral parser option |
| 134 |
// ignore any words at the beginning of column 3 (zero-based index) using a regular expression |
| 135 |
// additionally, if all column content contains the same character to ignore, a string can be |
| 136 |
// passed within this option, e.g. "Chapter " |
| 137 |
// the three zeros in the array are just placeholders ( [ , , , /^(\w+\s)/ ] works as well ) |
| 138 |
roman_ignore: [ 0, 0, 0, /^(\w+\s)/ ] |
| 139 |
|
| 140 |
}); |
| 141 |
|
| 142 |
});</pre> |
| 143 |
</div> |
| 144 |
|
| 145 |
<h3><a href="#">"roman-extract" parser</a></h3> |
| 146 |
<div> |
| 147 |
<ul> |
| 148 |
<li>This parser will attempt to extract out a roman numeral block from the cell content.</li> |
| 149 |
<li>It's not perfect. If the content contains two blocks of roman numerals, they will be combined. For example, |
| 150 |
<ul> |
| 151 |
<li>If a cell contains <code>X plus VII</code>, the parser will extract out <code>XVII</code> and return a value of 17.</li> |
| 152 |
<li>Or worse yet, if a cell contains <code>VI minus X</code>, the parser will extract out <code>VIX</code> which is not a valid roman numeral, so it will instead return the initial value of <code>VI minus X</code>. If this is the case, use the "roman-ignore" parser instead.</li> |
| 153 |
</ul> |
| 154 |
</li> |
| 155 |
</ul> |
| 156 |
<pre class="prettyprint lang-js">$(function() { |
| 157 |
|
| 158 |
$("table").tablesorter({ |
| 159 |
theme: 'blue', |
| 160 |
widgets: ['zebra'], |
| 161 |
headers: { |
| 162 |
4 : { sorter: 'roman-extract' } |
| 163 |
} |
| 164 |
}); |
| 165 |
|
| 166 |
});</pre> |
| 167 |
</div> |
| 168 |
|
| 169 |
</div> |
| 170 |
|
| 171 |
<h1>Demo</h1> |
| 172 |
|
| 173 |
<button type="button" class="toggleparsedvalue">toggle</button> parsed values within the column |
| 174 |
|
| 175 |
<div id="demo"><table> |
| 176 |
<thead> |
| 177 |
<tr> |
| 178 |
<th class="sorter-false" colspan="2">Pure Roman Numerals</th> |
| 179 |
<th class="sorter-false" colspan="2">Ignore Non-Roman Numerals</th> |
| 180 |
<th class="sorter-false">Extract Roman Numerals</th> |
| 181 |
</tr> |
| 182 |
<tr> |
| 183 |
<th class="sorter-roman">Short</th> |
| 184 |
<th class="sorter-roman">Long</th> |
| 185 |
<th class="sorter-roman-ignore">Ignore last (1) character *</th> |
| 186 |
<th class="sorter-roman-ignore">Ignore regex (/^(\w+\s)/)</th> |
| 187 |
<th class="sorter-roman-extract">Extract</th> |
| 188 |
</tr> |
| 189 |
</thead> |
| 190 |
<tbody> |
| 191 |
<tr><td>I</td><td>MDLXXXV</td><td>iiia</td><td>Mark I</td><td>2000 XXVII Sydney</td></tr> |
| 192 |
<tr><td>MXI</td><td>MDCLXVI</td><td>iiib</td><td>Mark IV</td><td>2012 XXX London</td></tr> |
| 193 |
<tr><td>XII</td><td>MMDCCCLVIII</td><td>ia</td><td>Mark V</td><td>2020 XXXII Tokyo</td></tr> |
| 194 |
<tr><td>CXI</td><td>MMCCI</td><td>va</td><td>Mark VII</td><td>2004 XXVIII Athens</td></tr> |
| 195 |
<tr><td>XXI</td><td>MDCCCXL</td><td>vi b</td><td>Mk III</td><td>1980 XXII Moscow</td></tr> |
| 196 |
<tr><td>XIII</td><td>MMMCXXIX</td><td>iva</td><td>Mod X</td><td>1972 XX Munich</td></tr> |
| 197 |
<tr><td>V</td><td>DLXXVII</td><td>via</td><td>Mod IV</td><td>2016 XXXI Rio de Janeiro</td></tr> |
| 198 |
<tr><td>X</td><td>MDCLXV</td><td>xia</td><td>Mk VIII</td><td>1996 XXVI Atlanta</td></tr> |
| 199 |
<tr><td>XI</td><td>MDXVIII</td><td>xiiz</td><td>Mod XII</td><td>1976 XXI Montreal</td></tr> |
| 200 |
<tr><td>CLXI</td><td>MDCCCLX</td><td>xd</td><td>Mk 0</td><td>1992 XXV Barcelona</td></tr> |
| 201 |
<tr><td>C</td><td>CCCXCI</td><td>iiic</td><td>Mk VI</td><td>1988 XXIV Seoul</td></tr> |
| 202 |
<tr><td>LV</td><td>MLXXX</td><td>xxf</td><td>Mk II</td><td>1984 XXIII Los Angeles</td></tr> |
| 203 |
<tr><td>IX</td><td>DCCLVII</td><td>lig</td><td>Mod L</td><td>2008 XXIX Beijing</td></tr> |
| 204 |
</tbody> |
| 205 |
</table></div> |
| 206 |
<small>* Ignoring the last letter (set number to ignore in <code>roman_ignore</code> option array; notice that "vi b" sorts before "via" - <strong>spaces do matter</strong>!)</small> |
| 207 |
<p></p> |
| 208 |
|
| 209 |
<h1>Page Header</h1> |
| 210 |
<div> |
| 211 |
<pre class="prettyprint lang-html"><!-- blue theme stylesheet with additional css styles added in v2.0.17 --> |
| 212 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 213 |
<!-- tablesorter plugin; requires jQuery --> |
| 214 |
<script src="../js/jquery.tablesorter.js"></script> |
| 215 |
|
| 216 |
<!-- load roman numeral parser --> |
| 217 |
<script src="../js/parsers/parser-roman.js"></script></pre> |
| 218 |
</div> |
| 219 |
|
| 220 |
<h1>Javascript</h1> |
| 221 |
<div id="javascript"> |
| 222 |
<pre class="prettyprint lang-javascript"></pre> |
| 223 |
</div> |
| 224 |
|
| 225 |
<h1>HTML</h1> |
| 226 |
<div id="html"> |
| 227 |
<pre class="prettyprint lang-html"></pre> |
| 228 |
</div> |
| 229 |
|
| 230 |
<script> |
| 231 |
$(function() { |
| 232 |
// add parsed values to order & value column |
| 233 |
addParsedValues($('table'), [0,1,2,3,4]); |
| 234 |
}); |
| 235 |
</script> |
| 236 |
|
| 237 |
</div> |
| 238 |
</body> |
| 239 |
</html> |