如何在一个页面上有多个jQuery TableSorter表 [英] How to have multiple jQuery TableSorter tables on a page
问题描述
当我的页面上只有1个表时,该插件可以正常工作.
The plugin is working fine when I only have 1 table on a page.
但是有两个,我得到一个错误:
But with two, I get an error:
未捕获的TypeError:无法设置未定义的属性"count"
Uncaught TypeError: Cannot set property 'count' of undefined
那是因为下面设置了sortList
选项.我将其设置为在第4列上进行排序,并且首先显示的aux_table
只有3列.但是它可以工作,而main_table
则不行.我如何让它们都起作用,或者只是第二个更重要的main_table
?
That's because of the sortList
option set below. I have it set to sort on the 4th column, and the aux_table
, displayed first, only has 3 columns. But it works and the main_table
doesn't. How do I get them both to work, or just the second, more important main_table
?
两个表都是类tablesorter
,它们具有不同的ID(main_table
和aux_table
).
Both tables are class tablesorter
and they have different ids (main_table
and aux_table
).
页面上的第一个表有效,而第二个表无效.这是我<head>
标签中的JS:
The first table on the page works, and the second doesn't. Here is the JS from my <head>
tag:
$(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]]
});
});
推荐答案
您需要更改代码以实例化每个单独表上的表排序器,以便为每个表指定单独的设置.
You need to change your code to instantiate the table sorter on each individual table, so that you can specify separate settings for each.
$("#table1").tablesorter({
sortList: [[3,1]]
});
$("#table2").tablesorter();
这篇关于如何在一个页面上有多个jQuery TableSorter表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!