// column 2: ignore last character (1) - for Roman "roman-ignore" numeral parser
// column 3: ignore characters that match the set regex (beginning of the string to first space)
roman_ignore: [ 0, 0, 1, /^(\w+\s)/ ]
});
});</script>
</head>
<body>
<divid="banner">
<h1>table<em>sorter</em></h1>
<h2>Roman Numeral Parser</h2>
<h3>Flexible client-side table sorting</h3>
<ahref="index.html">Back to documentation</a>
</div>
<divid="main">
<p></p>
<br>
<divid="root"class="accordion">
<h3><ahref="#">Notes</a></h3>
<div>
<ul>
<li>This parser (added <spanclass="version">v2.17.3</span>) will convert roman numerals into their decimal equivalent so the table column can be sorted correctly.</li>
<li>There are actually 3 separate parsers included with this script.
<ul>
<li>They are very similar, but were written to cover different use cases.</li>
<li> Refer to each in their separate sections below.</li>
</ul>
</li>
<li>This demo includes the stored roman numeral values within the table cells, toggle the view using the button directly above the table.</li>
</ul>
</div>
<h3><ahref="#">"roman" parser</a></h3>
<div>
<ul>
<li>This parser is optimized for columns that contain only roman numerals.</li>
<li>In the demo below, this parser is used for the "Short" and "Long" columns.</li>
<li>This parser has no option settings.</li>
</ul>
<preclass="prettyprint lang-js">$(function() {
$("table").tablesorter({
theme: 'blue',
widgets: ['zebra'],
headers: {
0 : { sorter: 'roman' },
1 : { sorter: 'roman' }
}
});
});</pre>
</div>
<h3><ahref="#">"roman-ignore" parser</a></h3>
<div>
This parser is designed to use the <code>roman_ignore</code> option to either:
<h4>Ignore The Last "X" Characters</h4>
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):
<preclass="prettyprint lang-js">$(function() {
$("table").tablesorter({
theme: 'blue',
widgets: ['zebra'],
headers: {
2 : { sorter: 'roman-ignore' }
},
// roman numeral parser option
// ignore the last (1) character(s) in column 2 (zero-based index)
// the two zeros in the array are just placeholders ( [ , , 1 ] works as well )
roman_ignore: [ 0, 0, 1 ]
});
});</pre>
<h4>Remove Non-Roman Numerals</h4>
For cells that contain a bit more complex layout, you can define a regular expression to ignore (remove) certain parts of the content.<br>
<br>
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>
<br>
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).
<preclass="prettyprint lang-js">$(function() {
$("table").tablesorter({
theme: 'blue',
widgets: ['zebra'],
headers: {
3 : { sorter: 'roman-ignore' }
},
// roman numeral parser option
// ignore any words at the beginning of column 3 (zero-based index) using a regular expression
// additionally, if all column content contains the same character to ignore, a string can be
// passed within this option, e.g. "Chapter "
// the three zeros in the array are just placeholders ( [ , , , /^(\w+\s)/ ] works as well )
roman_ignore: [ 0, 0, 0, /^(\w+\s)/ ]
});
});</pre>
</div>
<h3><ahref="#">"roman-extract" parser</a></h3>
<div>
<ul>
<li>This parser will attempt to extract out a roman numeral block from the cell content.</li>
<li>It's not perfect. If the content contains two blocks of roman numerals, they will be combined. For example,
<ul>
<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>
<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>
</ul>
</li>
</ul>
<preclass="prettyprint lang-js">$(function() {
$("table").tablesorter({
theme: 'blue',
widgets: ['zebra'],
headers: {
4 : { sorter: 'roman-extract' }
}
});
});</pre>
</div>
</div>
<h1>Demo</h1>
<buttontype="button"class="toggleparsedvalue">toggle</button> parsed values within the column
<divid="demo"><table>
<thead>
<tr>
<thclass="sorter-false"colspan="2">Pure Roman Numerals</th>
<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>