Demo
Name |
Major |
Gender |
English |
Japanese |
Calculus |
Overall grades |
Student01 |
Languages |
male |
80 |
70 |
75 |
bad |
Student02 |
Mathematics |
male |
90 |
88 |
100 |
good |
Student03 |
Languages |
female |
85 |
95 |
80 |
medium |
Javascript
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'grades',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return s.toLowerCase().replace(/good/,2).replace(/medium/,1).replace(/bad/,0);
},
// set type, either numeric or text
type: 'numeric'
});
$(function() {
$("table").tablesorter({
headers: {
6: {
sorter:'grades'
}
}
});
});
HTML
<table cellspacing="1" class="tablesorter">
<thead>>
<tr>
<th>name</th>
<th>major</th>
<th>gender</th>
<th>english</th>
<th>japanese</th>
<th>calculus</th>
<th>overall grades</th>
</tr>
</thead>
<tbody>
<tr>
<td>student01</td>
<td>languages</td>
<td>male</td>
<td>80</td>
<td>70</td>
<td>75</td>
<td>bad</td>
</tr>
<tr>
<td>student02</td>
<td>mathematics</td>
<td>male</td>
<td>90</td>
<td>88</td>
<td>100</td>
<td>good</td>
</tr>
<tr>
<td>student03</td>
<td>languages</td>
<td>female</td>
<td>85</td>
<td>95</td>
<td>80</td>
<td>medium</td>
</tr>
</tbody>
</table>