jQuery Tablesorter - sorting by clicking a link

两盒软妹~` 提交于 2019-12-11 04:16:09

问题


I'm using jQuery Tablesorter to sort a table and everything works as expected. What I'd like to do is add a link above my table that says something along the lines of "Sort by Price" and when the user clicks the link I want the "Price" column to sort. Additionally, if they click it again, it would sort the price the other way. Is this possible?

Thanks! Manoj


回答1:


From 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; 
    }); 
});


来源:https://stackoverflow.com/questions/2024004/jquery-tablesorter-sorting-by-clicking-a-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!