Remove jQuery tablesorter from table

2020-02-06 18:52发布

I am using the jQuery tablesorter (http://tablesorter.com).

After being applied to a table by $('#myTable').tablesorter(), how can I remove it again from the table?

4条回答
迷人小祖宗
2楼-- · 2020-02-06 19:08

Latest version of table sorter library provides Destroy method

From version 2.16 destroy() method has been added in table sorter library, use this method to remove tablesorter from the table.

查看更多
成全新的幸福
3楼-- · 2020-02-06 19:13

There isn't a built-in function to do this, but you could remove the class names and event bindings to stop its functioning... try something like this:

$('table')
 .unbind('appendCache applyWidgetId applyWidgets sorton update updateCell')
 .removeClass('tablesorter')
 .find('thead th')
 .unbind('click mousedown')
 .removeClass('header headerSortDown headerSortUp');

The above won't work if you have the pager plugin running.

查看更多
\"骚年 ilove
4楼-- · 2020-02-06 19:13

use the function given below onclick event of remove shorting element

function removeTableShorter(){
$("#myTable").tablesorter({ 
headers: {
 0: {sorter: false},
 1: {sorter: false},
 2: {sorter: false},
 3: {sorter: false},
 4: {sorter: false},
 5: {sorter: false}
}
});
$('#myTable th').removeAttr('class');}

u may increase the number of headers according the number of columns of table.

查看更多
ゆ 、 Hurt°
5楼-- · 2020-02-06 19:20

tablesorter2.0

$("#table").trigger("destroy");

or if you just in need to update all after appending new thead :

$("#table").trigger("updateAll");

-> http://mottie.github.io/tablesorter/docs/index.html

查看更多
登录 后发表回答