【问题标题】:jQuery Tablesorter - sorting by clicking a linkjQuery Tablesorter - 通过单击链接进行排序
【发布时间】:2010-01-07 22:02:39
【问题描述】:

我正在使用 jQuery Tablesorter 对表格进行排序,一切都按预期工作。我想做的是在我的表格上方添加一个链接,上面写着“按价格排序”的内容,当用户单击该链接时,我希望“价格”列进行排序。此外,如果他们再次单击它,它将以另一种方式对价格进行排序。这可能吗?

谢谢! 马诺吉

【问题讨论】:

    标签: jquery jquery-plugins tablesorter


    【解决方案1】:

    来自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; 
        }); 
    });
    

    【讨论】:

    • 谢谢,乔尔 - 效果很好。有没有办法让它切换,所以如果我再次点击链接,它会以另一种方式排序?现在,当我单击链接时,它会排序,但如果我再次单击它,则没有任何反应。非常感谢。
    • 您可以将当前的排序状态保存在一个变量中,并在设置前切换它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 2014-03-02
    相关资源
    最近更新 更多