I have the next simple table and I use jQuery tablesorter for order by columns:
<table class="tablesorter" id="tableinvoices">
<thead>
<tr>
<th>Name</th>
<th>LastName</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td><b id="n1">Sonia</b></td>
<td><b id="l1">Soto</b></td>
<td><b id="a1">20</b></td>
</tr>
<tr>
<td><b id="n2">Carlos</b></td>
<td><b id="l2">Rodriguez</b></td>
<td><b id="a2">21</b></td>
</tr>
<tr>
<td><b id="n3">Borja</td>
<td><b id="l3">Valera</td>
<td><b id="a3">21</td>
</tr>
</tbody>
</table>
If I click in Name, instead of order by values of td, order by id.
How do I order by the values?
Thanks for help and sorry for my bad english.
Here is a solution: http://jsfiddle.net/shtrih/Mh75v/
$(document).ready(function() {
// call the tablesorter plugin
$("table").tablesorter({
// define a custom text extraction function
textExtraction: function(node) {
// extract data from id and return it
console.log(node.childNodes[0].innerHTML); // Make sure the output values
return node.childNodes[0].innerHTML;
}
});
});
I've used this example: http://tablesorter.com/docs/example-option-text-extraction.html