• In v2.19.0, 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 3000..

  • This widget will only work in tablesorter version 2.8+ and jQuery version 1.7+.
  • Make sure to include the CSS shown below to maintain the alignment.
  • *NOTE* if the table cell becomes too narrow, the alignment will not be maintained & some content may overflow into the next/previous cell (the widget css does include overflow:hidden on the wrapper, so some content will be hidden instead of overflowing).
  • Until the day that text-align: '.'; becomes standard (ref), if ever, this widget might prove useful.

Demo

Animals align index:
1 (only indexes of 1 or 2 will work)
Sites align index:
1 (only indexes of 1 - 3 will work
Sites adjust value:
0
AlphaNumeric
Numeric
Animals ( "data-align-index" : 1 )
Sites ( "data-align-index" : 1, "data-align-adjust" : 1 )
abc 123 .423475 Koala = cute = cudley search.google.com
abc 1 23.4 Ox = stinky mail.yahoo.com
abc 9 1.0 Girafee = tall http://www.facebook.com
zyx 24 7.67 Bison = burger http://internship.whitehouse.gov/
abc 11 3000 Chimp = banana lover about.ucla.edu/
abc 2 56.5 Elephant = unforgetable http://www.wikipedia.org/
abc 9 15.5 Lion = rawr rental.nytimes.com/index.html
ABC 10 87.20000 Zebra = stripey http://android.google.com
zyx 1 999.1 Koala = cute, again! http://irsmrt.mit.edu/
zyx 12 .2 Llama = llove it http://aliens.nasa.gov/

Page Header

<!-- 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>

Script

$(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
}
});

});

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;
}

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>