mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-12-05 05:04:20 +00:00
456 lines
16 KiB
HTML
456 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>jQuery plugin: Tablesorter 2.0 - Align Character Widget</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">
|
|
<link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
|
|
<script src="js/jquery-ui.min.js"></script>
|
|
<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/jquery.tablesorter.widgets.js"></script>
|
|
|
|
<script src="../js/widgets/widget-alignChar.js"></script>
|
|
|
|
<style>
|
|
/* demo stuff */
|
|
.accordion th:nth-child(2) {
|
|
width: 140px;
|
|
}
|
|
#demo th {
|
|
width: 25%;
|
|
}
|
|
</style>
|
|
|
|
<style id="css">/* CSS needed for this widget */
|
|
.ts-align-wrap {
|
|
white-space: nowrap;
|
|
width: 100%;
|
|
overflow: hidden;
|
|
}
|
|
.ts-align-wrap, .ts-align-left, .ts-align-right {
|
|
display: inline-block;
|
|
-moz-box-sizing: border-box;
|
|
-webkit-box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
}
|
|
.ts-align-left {
|
|
text-align:right;
|
|
}
|
|
.ts-align-right {
|
|
text-align:left;
|
|
}
|
|
/* optional - colorize alignment character in Animals column */
|
|
td:nth-child(3) .ts-align-right i {
|
|
color: red;
|
|
}</style>
|
|
|
|
<script id="js">$(function() {
|
|
|
|
$("table").tablesorter({
|
|
theme: 'blue',
|
|
widgets: ['zebra', 'alignChar'],
|
|
widgetOptions : {
|
|
alignChar_wrap : '<i/>',
|
|
alignChar_charAttrib : 'data-align-char',
|
|
alignChar_indexAttrib : 'data-align-index',
|
|
alignChar_adjustAttrib : 'data-align-adjust' // percentage width adjustments
|
|
}
|
|
});
|
|
|
|
});
|
|
</script>
|
|
</head>
|
|
<body id="align">
|
|
|
|
<div id="banner">
|
|
<h1>table<em>sorter</em></h1>
|
|
<h2>Align Character Widget</h2>
|
|
<h3>Flexible client-side table sorting</h3>
|
|
<a href="index.html">Back to documentation</a>
|
|
</div>
|
|
|
|
<div id="main">
|
|
|
|
<p></p>
|
|
<br>
|
|
|
|
<div class="accordion">
|
|
|
|
<h3><a href="#">Notes</a></h3>
|
|
<div>
|
|
<ul>
|
|
<li>In <span class="version">v2.19.0</span>, if there is nothing to the right of the set align character, then the align character will not be added; this prevents hanging decimals like <code>3000.</code>.<p></p></li>
|
|
<li>This widget will <strong>only work</strong> in tablesorter version 2.8+ and jQuery version 1.7+.</li>
|
|
<li>Make sure to include the CSS shown below to maintain the alignment.</li>
|
|
<li><span class="label warning">*NOTE*</span> if the table cell becomes too narrow, the alignment <strong>will not</strong> be maintained & some content may overflow into the next/previous cell (the widget css does include <code>overflow:hidden</code> on the wrapper, so some content will be hidden instead of overflowing).</li>
|
|
<li>Until the day that <code>text-align: '.';</code> becomes standard (<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-align">ref</a>), if ever, this widget might prove useful.</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<h3><a href="#">Options</a></h3>
|
|
<div>
|
|
<h3>Align Character (alignChar) widget default options (added inside of tablesorter <code>widgetOptions</code>)</h3>
|
|
<div>
|
|
<span class="label label-info">TIP!</span> Click on the link in the Option column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location.
|
|
</div>
|
|
<table class="tablesorter-blue">
|
|
<colgroup><col style="width:135px"></colgroup>
|
|
<thead>
|
|
<tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><a href="#" class="permalink">alignChar_wrap</a></td>
|
|
<td><code>''</code></td>
|
|
<td>
|
|
This option allows you to wrap the alignment character in any HTML:
|
|
<div class="collapsible">
|
|
<br>
|
|
When the widget completes the alignment, it is basically splitting the content of the table cell into two halves, and wrapping it in a span element. Below is an example of a modified cell showing all contents; it's from the "Animals" column (the cell that contains "Ox = stinky")
|
|
<pre class="prettyprint lang-html"><td>
|
|
<span class="ts-align-wrap">
|
|
<span class="ts-align-left" style="min-width:37%">Ox&nbsp;</span>
|
|
<span class="ts-align-right" style="min-width:63%">=&nbsp;stinky</span>
|
|
</span>
|
|
</td></pre>
|
|
When this option is set with some HTML:
|
|
<br><pre class="prettyprint lang-js">alignChar_wrap : '<i/>'</pre>
|
|
it results in this layout:
|
|
<pre class="prettyprint lang-html"><td>
|
|
<span class="ts-align-wrap">
|
|
<span class="ts-align-left" style="min-width:37%">Ox&nbsp;</span>
|
|
<span class="ts-align-right" style="min-width:63%">
|
|
<i>=</i>&nbsp;stinky
|
|
</span>
|
|
</span>
|
|
</td></pre>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="#" class="permalink">alignChar_charAttrib</a></td>
|
|
<td><code>'data-align-char'</code></td>
|
|
<td>
|
|
This option points to the header data-attribute which contains the desired alignment character.
|
|
<div class="collapsible">
|
|
<br>
|
|
Add it to the header as follows:
|
|
<pre class="prettyprint lang-html"><th data-align-char=".">Numeric</th></pre>
|
|
The <code>data-align-char</code> data-attribute contains the actual character to align. There is no default alignment character, so if this data-attribute is undefined, the column will be ignored.<br>
|
|
<br>
|
|
<span class="label warning">*NOTE*</span> if wanting to align the content on a space (see the "AlphaNumeric" column), use <code>&nbsp;</code> instead of a regular space because all spaces within the content are replaced by non-breaking spaces.
|
|
<pre class="prettyprint lang-html"><th data-align-char="&nbsp;">AlphaNumeric</th></pre>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="#" class="permalink">alignChar_indexAttrib</a></td>
|
|
<td><code>'data-align-index'</code></td>
|
|
<td>This option points to the header data-attribute which contains the desired alignment character index (<strong>one-based index</strong>).
|
|
<div class="collapsible">
|
|
<ul>
|
|
<li>What that means is if your data has multiple periods, like in the URLs of the sites column below, you can tell the widget which period to line-up on.</li>
|
|
<li>The alignment may seem to act incorrectly, if your data doesn't have enough periods to line up on, but it's doing the best it can! For example, in the sites column below, a table cell contains <code>"rental.nytimes.com/index.html"</code>. This URL has three periods, while all other cells in that column only contain two. When the <code>data-align-index</code> is set to <code>"3"</code>, the widget aligns the content on that third period. All of the other columns only have two, so they all align on their last period. Does that make it clear?</li>
|
|
<li>Try adjusting the sliders in this demo to change the <code>data-align-index</code> of the "Animals" and "Sites" columns to see how this works.</li>
|
|
</ul>
|
|
Add this attribute to the header as follows:
|
|
<pre class="prettyprint lang-html"><th data-align-char="=" data-align-index="1">Animals</th></pre>
|
|
The <code>data-align-index</code> data-attribute contains the actual character index. The index defaults to "1" if this data-attribute is undefined.
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="#" class="permalink">alignChar_adjustAttrib</a></td>
|
|
<td><code>'data-align-adjust'</code></td>
|
|
<td>This option allows you to tweak the horizontal position of the aligned cell content.
|
|
<div class="collapsible">
|
|
<ul>
|
|
<li>Here is an example of a modified cell showing its contents; it's from the "Numeric" column (the cell that contains "87.20000"):
|
|
<pre class="prettyprint lang-html"><td>
|
|
<span class="ts-align-wrap">
|
|
<span class="ts-align-left" style="min-width:36%">87</span>
|
|
<span class="ts-align-right" style="min-width:64%">.20000</span>
|
|
</span>
|
|
</td></pre>As you can see, the "87" (integer-part) is in a "ts-align-left" span, set with a <code>text-align: right;</code> (it's on the left, but right aligned)<br>
|
|
The ".20000" (fractional-part) is in a "ts-align-right" span, set with a <code>text-align: left;</code> (opposite of the other one)!<br>
|
|
</li>
|
|
<li>So in the above example, the left side is set to a width of "36%" and the right to "64%" (adding up to 100%), which "sort-of" centers the aligned character.</li>
|
|
<li>If you don't want to move the position of the aligned character, you can set the <code>data-align-adjust</code> data-attribute with a percentage change. This value (positive or negative) will be added to the "ts-align-left" span, and subtracted from the "ts-align-right" span.</li>
|
|
<li>Try adjusting the sliders in this demo to change the <code>data-align-adjust</code> of the "Sites" column to see how this works.</li>
|
|
</ul>
|
|
Add this attribute to the header as follows:
|
|
<pre class="prettyprint lang-html"><th data-align-char="." data-align-adjust="10">Numeric</th></pre>
|
|
The <code>data-align-adjust</code> data-attribute contains a percentage value (without the percent sign). The adjustment defaults to "0" if this data-attribute is undefined.
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h3><a href="#">CSS</a></h3>
|
|
<div>
|
|
The following is *required* css. Without it, the alignment will be all wrong.
|
|
<div id="css">
|
|
<pre class="prettyprint lang-css"></pre>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<p></p>
|
|
|
|
<h1>Demo</h1>
|
|
|
|
<span class="demo-label">Animals align index:</span> <div id="slider0"></div> <span class="bright">1</span> (only indexes of 1 or 2 will work)<br>
|
|
<span class="demo-label">Sites align index:</span> <div id="slider1"></div> <span class="bright">1</span> (only indexes of 1 - 3 will work<br>
|
|
<span class="demo-label">Sites adjust value:</span> <div id="slider2"></div> <span class="bright">0</span>
|
|
|
|
<div id="demo"><table class="tablesorter">
|
|
<thead>
|
|
<tr>
|
|
<th data-align-char=" ">AlphaNumeric</th>
|
|
<th data-align-char="." data-align-adjust="0">Numeric</th>
|
|
<th data-align-char="=" data-align-index="1">Animals</th>
|
|
<th data-align-char="." data-align-index="1">Sites</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>abc 123</td>
|
|
<td>.423475</td>
|
|
<td>Koala = cute = cudley</td>
|
|
<td>search.google.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 1</td>
|
|
<td>23.4</td>
|
|
<td>Ox = stinky</td>
|
|
<td>mail.yahoo.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 9</td>
|
|
<td>1.0</td>
|
|
<td>Girafee = tall</td>
|
|
<td>http://www.facebook.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>zyx 24</td>
|
|
<td>7.67</td>
|
|
<td>Bison = burger</td>
|
|
<td>http://internship.whitehouse.gov/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 11</td>
|
|
<td>3000</td>
|
|
<td>Chimp = banana lover</td>
|
|
<td>about.ucla.edu/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 2</td>
|
|
<td>56.5</td>
|
|
<td>Elephant = unforgetable</td>
|
|
<td>http://www.wikipedia.org/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 9</td>
|
|
<td>15.5</td>
|
|
<td>Lion = rawr</td>
|
|
<td>rental.nytimes.com/index.html</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ABC 10</td>
|
|
<td>87.20000</td>
|
|
<td>Zebra = stripey</td>
|
|
<td>http://android.google.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>zyx 1</td>
|
|
<td>999.1</td>
|
|
<td>Koala = cute, again!</td>
|
|
<td>http://irsmrt.mit.edu/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>zyx 12</td>
|
|
<td>.2</td>
|
|
<td>Llama = llove it</td>
|
|
<td>http://aliens.nasa.gov/</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
|
|
<h1>Page Header</h1>
|
|
<div>
|
|
<pre class="prettyprint lang-html"><!-- Tablesorter: required -->
|
|
<link href="../css/theme.blue.css" rel="stylesheet">
|
|
<script src="../js/jquery.tablesorter.js"></script>
|
|
<script src="../js/jquery.tablesorter.widgets.js"></script>
|
|
|
|
<!-- Align Character widget -->
|
|
<script src="../js/widgets/widget-alignChar.js"></script></pre>
|
|
</div>
|
|
|
|
<h1>Script</h1>
|
|
<div id="javascript">
|
|
<pre class="prettyprint lang-js"></pre>
|
|
</div>
|
|
|
|
<h1>CSS</h1>
|
|
<div id="css">
|
|
<pre class="prettyprint lang-css"></pre>
|
|
</div>
|
|
|
|
<h1>HTML</h1>
|
|
<div>
|
|
<pre class="prettyprint lang-html"><table class="tablesorter">
|
|
<thead>
|
|
<tr>
|
|
<th data-align-char="&nbsp;">AlphaNumeric</th>
|
|
<th data-align-char="." data-align-adjust="0">Numeric</th>
|
|
<th data-align-char="=" data-align-index="1">Animals</th>
|
|
<th data-align-char="." data-align-index="1">Sites</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>abc 123</td>
|
|
<td>.423475</td>
|
|
<td>Koala = cute = cudley</td>
|
|
<td>search.google.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 1</td>
|
|
<td>23.4</td>
|
|
<td>Ox = stinky</td>
|
|
<td>mail.yahoo.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 9</td>
|
|
<td>1.0</td>
|
|
<td>Girafee = tall</td>
|
|
<td>http://www.facebook.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>zyx 24</td>
|
|
<td>7.67</td>
|
|
<td>Bison = burger</td>
|
|
<td>http://internship.whitehouse.gov/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 11</td>
|
|
<td>3000</td>
|
|
<td>Chimp = banana lover</td>
|
|
<td>about.ucla.edu/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 2</td>
|
|
<td>56.5</td>
|
|
<td>Elephant = unforgetable</td>
|
|
<td>http://www.wikipedia.org/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>abc 9</td>
|
|
<td>15.5</td>
|
|
<td>Lion = rawr</td>
|
|
<td>rental.nytimes.com/index.html</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ABC 10</td>
|
|
<td>87.20000</td>
|
|
<td>Zebra = stripey</td>
|
|
<td>http://android.google.com</td>
|
|
</tr>
|
|
<tr>
|
|
<td>zyx 1</td>
|
|
<td>999.1</td>
|
|
<td>Koala = cute, again!</td>
|
|
<td>http://irsmrt.mit.edu/</td>
|
|
</tr>
|
|
<tr>
|
|
<td>zyx 12</td>
|
|
<td>0.2</td>
|
|
<td>Llama = llove it</td>
|
|
<td>http://aliens.nasa.gov/</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></pre>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
/* DEMO ONLY CODE */
|
|
$(function(){
|
|
var $table = $('#demo table'),
|
|
c = $table[0].config,
|
|
$animals = c.$headers.eq(2),
|
|
$sites = c.$headers.eq(3);
|
|
$animals.find('.tablesorter-header-inner')[0].innerHTML += ' ( "data-align-index" : <span></span> )';
|
|
$sites.find('.tablesorter-header-inner')[0].innerHTML += ' ( "data-align-index" : <span></span>, "data-align-adjust" : <span></span> )';
|
|
$( "#slider0" ).slider({
|
|
value: 1,
|
|
min: 0,
|
|
max: 3,
|
|
step: 1,
|
|
create: function(){
|
|
$animals.find('span').html( $animals.attr('data-align-index') );
|
|
},
|
|
slide: function( event, ui ) {
|
|
$animals
|
|
.attr('data-align-index', ui.value)
|
|
.find('span').html( ui.value );
|
|
$('.bright:eq(0)').html( ui.value );
|
|
$table.trigger('refreshAlign');
|
|
}
|
|
});
|
|
$( "#slider1" ).slider({
|
|
value: 1,
|
|
min: 0,
|
|
max: 4,
|
|
step: 1,
|
|
create: function(){
|
|
$sites.find('span').html( $sites.attr('data-align-index') );
|
|
},
|
|
slide: function( event, ui ) {
|
|
$sites
|
|
.attr('data-align-index', ui.value)
|
|
.find('span:eq(0)').html( ui.value );
|
|
$('.bright:eq(1)').html( ui.value );
|
|
$table.trigger('refreshAlign');
|
|
}
|
|
});
|
|
$( "#slider2" ).slider({
|
|
value: 0,
|
|
min: -30,
|
|
max: 30,
|
|
step: 5,
|
|
create: function(){
|
|
$sites.find('span').html( $sites.attr('data-align-index') );
|
|
},
|
|
slide: function( event, ui ) {
|
|
$sites
|
|
.attr('data-align-adjust', ui.value)
|
|
.find('span:eq(1)').html( ui.value );
|
|
$('.bright:eq(2)').html( ui.value );
|
|
$table.trigger('refreshAlign');
|
|
}
|
|
});
|
|
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
|