2010-01-07 55 views
1

我正在使用jQuery Tablesorter对表进行排序,并且所有内容都按预期工作。我想要做的是在我的表格上方添加一个链接,说明“按价格排序”一行,并且当用户单击链接时,我希望“价格”列进行排序。另外,如果他们再次点击它,它会以另一种方式对价格进行分类。这可能吗?jQuery Tablesorter - 通过单击链接排序

谢谢! 马诺

回答

0

tablesorter.com

$(document).ready(function() { 
    $("table").tablesorter(); 
    $("#trigger-link").click(function() { 
     // set sorting column and direction, this will sort on the first and third column the column index starts at zero 
     var sorting = [[0,0],[2,0]]; 
     // sort on the first column 
     $("table").trigger("sorton",[sorting]); 
     // return false to stop default link action 
     return false; 
    }); 
}); 
+0

谢谢,乔尔 - 的作品真的很好。有没有办法让它切换,所以如果我再次点击链接,它会以另一种方式排序?现在,当我点击链接时,它会排序,但如果我再次点击它,什么都不会发生。 非常感谢。 – 2010-01-07 22:17:14

+0

您可以将排序的当前状态保存在变量中并在设置之前切换。 – Joel 2010-01-07 23:05:07