如何在页面上有多个jQuery TableSorter表

当我在页面上只有一个表时,插件工作正常。

但有两个,我得到一个错误:

未捕获的TypeError:无法设置未定义的属性’count’

这是因为下面设置了sortList选项。 我将它设置为在第4列上排序,并且aux_table显示的aux_table只有3列。 但它有效,而main_table则没有。 我如何让他们两个都工作,或者只是第二个更重要的main_table

两个表都是类tablesorter ,它们有不同的id( main_tableaux_table )。

页面上的第一个表工作,第二个表没有。 这是我的标签中的JS:

 $(document).ready(function() { // call the tablesorter plugin $("table").tablesorter({ // sort on the 4th column (index 3) column, DESC (1). ASC is (0). sortList: [[3,1]] }); }); 

您需要更改代码以在每个表上实例化表分类器,以便您可以为每个表指定单独的设置。

 $("#table1").tablesorter({ sortList: [[3,1]] }); $("#table2").tablesorter(); 

是的,您可以在一个页面中添加多个表。 您可以如下所示在wrap中添加每个表,并且可以单独添加分页和排序function。

  $(document).ready(function() { $('.pearl-container').each(function(i) { $(this).children(".myTable") .tablesorter({ widthFixed: true, widgets: ['zebra'] }) .tablesorterPager({ container: $(this).children(".pager"), size: 5 }); }); }); 

在课堂上选择怎么样?

 $(".tablesorter").tablesorter(); 

如果需要对多个表进行排序..