javascript - jQuery tablesorter sort by column id instead of column number -
i have html table i'm sorting jquery tablesorter. have external link sorts table name using javascript. within javascript function though, have sort column 0 instead of saying sort name column.
how can modify have below don't have remember name column 0 in javascript?
$('document').ready(function(){ $('table#classes_table').tablesorter(); $("#sort-link").click(function() { //how can sort "name" instead of having remember name column 0 var sorting = [[0,0] $("table").trigger("sorton",[sorting]); return false; }); }); <a href="#" id="sort-link">sort name</a><br><br> <table class="tablesorter" id="classes_table"> <thead> <tr> <th>name</th> <th>school</th> <th>students</th> </tr> </thead> <tbody> <tr> <td>class1</td> <td>school5 </td> <td>32</td> </tr> <tr> <td>class2</td> <td>school1</td> <td>7</td> </tr> </tbody> </table>
you use hack...
var columnindex = $('table > thead > tr > th:contains("name")').index();
Comments
Post a Comment