Exclude a column from being sorted using jQuery tablesorter

后端 未结 8 1770
有刺的猬
有刺的猬 2021-02-01 21:30

I am looking for a way to exclude a single column from being sorted using jQuery\'s tablesorter plugin. Specifically, I have a fairly large table and would like to keep a \"row

8条回答
  •  独厮守ぢ
    2021-02-01 21:58

    The answer of Brian Fisher is correct, but it is too slow in large tables (+1600 rows in my example). I improved the way of iterating through every rows. Everything else is the same.

    $(function() {
        // add new widget called indexFirstColumn
        $.tablesorter.addWidget({
            // give the widget a id
            id: "indexFirstColumn",
            // format is called when the on init and when a sorting has finished
            format: function(table) {               
                // loop all tr elements and set the value for the first column  
                $(table).find("tr td:first-child").each(function(index){
                    $(this).text(index+1);
                })                                  
            }
        });
    
        $("table").tablesorter({
            widgets: ['zebra','indexFirstColumn']
        });
    });
    

提交回复
热议问题