NOTE!
- In tablesorter version 2.0.5 and older, only the metadata and headers options methods were available to set the parsers.
- In versions 2.0.11+, parsers could be set using class names.
- Currently (versions 2.3+), parsers can be set using any of the following methods (they all do the same thing), in order of priority:
- jQuery data
data-sorter="text"
(see the Javascript block below on how to set it directly). - metadata
class="{ sorter: "text" }"
. This requires the metadata plugin. - headers option
headers : { 0 : { sorter: "text" } }
. - header class name
class="sorter-text"
.
- jQuery data
Demo
First Name |
Last Name |
Age |
Total |
Discount |
Date |
---|---|---|---|---|---|
Peter | Parker | 28 | ($9.99) | 20% | Jul 6, 2006 8:14 AM |
John | 33 | $19.99 | 25% | Dec 10, 2002 5:14 AM | |
Clark | Kent | 18 | 44% | Jan 12, 2003 11:14 AM | |
Bruce | Almighty | 45 | $153.19 | 44% | |
Bruce | Evans | 22 | N/A | Jan 18, 2007 9:12 AM | |
Evans | 18 | $13.19 | 11% | Jul 6, 2006 8:14 AM |
Javascript
$(function(){ $("table").tablesorter({ theme: 'blue' }); });
HTML
<table class="tablesorter"> <thead> <tr> <th class="sorter-text">First Name</th> <th class="sorter-text">Last Name</th> <th class="sorter-false">Age</th> <th class="sorter-currency string-min">Total</th> <!-- class="string-min" treats strings in this numeric column as a large negative number --> <th class="sorter-percent empty-top">Discount</th> <!-- class="empty-top" sorts empty cells to the top --> <th class="sorter-usLongDate">Date</th> </tr> </thead> <tbody> <tr> <td>Peter</td> <td>Parker</td> <td>28</td> <td>($9.99)</td> <td>20%</td> <td>Jul 6, 2006 8:14 AM</td> </tr> <tr> <td>John</td> <td></td> <td>33</td> <td>$19.99</td> <td>25%</td> <td>Dec 10, 2002 5:14 AM</td> </tr> <tr> <td>Clark</td> <td>Kent</td> <td>18</td> <td></td> <td>44%</td> <td>Jan 12, 2003 11:14 AM</td> </tr> <tr> <td>Bruce</td> <td>Almighty</td> <td>45</td> <td>$153.19</td> <td>44%</td> <td></td> </tr> <tr> <td>Bruce</td> <td>Evans</td> <td>22</td> <td>N/A</td> <td></td> <td>Jan 18, 2007 9:12 AM</td> </tr> <tr> <td></td> <td>Evans</td> <td>18</td> <td>$13.19</td> <td>11%</td> <td>Jul 6, 2006 8:14 AM</td> </tr> </tbody> </table>