Notes
- 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.
Options
Align Character (alignChar) widget default options (added inside of tablesorter widgetOptions
)
TIP! Click on the link in the Option column to reveal full details (or toggle|show|hide all) or double click to update the browser location.
Option | Default | Description |
---|---|---|
alignChar_wrap | '' |
This option allows you to wrap the alignment character in any HTML:
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") <td> <span class="ts-align-wrap"> <span class="ts-align-left" style="min-width:37%">Ox </span> <span class="ts-align-right" style="min-width:63%">= stinky</span> </span> </td>When this option is set with some HTML: alignChar_wrap : '<i/>'it results in this layout: <td> <span class="ts-align-wrap"> <span class="ts-align-left" style="min-width:37%">Ox </span> <span class="ts-align-right" style="min-width:63%"> <i>=</i> stinky </span> </span> </td> |
alignChar_charAttrib | 'data-align-char' |
This option points to the header data-attribute which contains the desired alignment character.
Add it to the header as follows: <th data-align-char=".">Numeric</th>The data-align-char 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.*NOTE* if wanting to align the content on a space (see the "AlphaNumeric" column), use instead of a regular space because all spaces within the content are replaced by non-breaking spaces.
<th data-align-char=" ">AlphaNumeric</th> |
alignChar_indexAttrib | 'data-align-index' |
This option points to the header data-attribute which contains the desired alignment character index (one-based index).
<th data-align-char="=" data-align-index="1">Animals</th>The data-align-index data-attribute contains the actual character index. The index defaults to "1" if this data-attribute is undefined.
|
alignChar_adjustAttrib | 'data-align-adjust' |
This option allows you to tweak the horizontal position of the aligned cell content.
<th data-align-char="." data-align-adjust="10">Numeric</th>The data-align-adjust data-attribute contains a percentage value (without the percent sign). The adjustment defaults to "0" if this data-attribute is undefined.
|
CSS
The following is *required* css. Without it, the alignment will be all wrong.
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 | Sites |
---|---|---|---|
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
CSS
HTML
<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>0.2</td> <td>Llama = llove it</td> <td>http://aliens.nasa.gov/</td> </tr> </tbody> </table>