jQuery tablesorter.js错误行600

时间:2012-09-08 23:36:35

标签: jquery tablesorter


我想使用tablesorter.js

在我启动$("#myTable").tablesorter();时在FireBug中,它返回[table#myTable.table]

但是当我想要使用$("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );进行排序时,它会返回以下错误:

TypeError: table.config.parsers is undefined
...tion("text", "asc", c) : makeSortFunction("text", "desc", c)) : ((order == 0) ? ...
jquery.tablesorter.js (ligne 600)

页面启动时没有错误,我使用ready函数来启动tableorter。

这是一个简短的版本:

<script type="text/javascript" src="/static/js/jquery.tablesorter.js"></script>
<script type='text/javascript'>
$(function() { 
   $("#myTable").tablesorter(); 
});
</script>

<table id="myTable" class="table table-condensed table-striped tablesorter">
 <thead>
  <tr>
   <th></th>
   <th>Nom</th>
   <th>Taille</th>
  </tr>
 </thead>
 <tbody>

 </tbody>
</table>

我使用twitter的bootstrap。

2 个答案:

答案 0 :(得分:2)

不应重新初始化插件以更改表上的排序,而应在表上触发sorton事件。请参阅this demo,然后尝试以下代码:

var sorting = [[0,0], [1,0]];

// note: the square brackets around sorting are required!
$("table").trigger("sorton", [sorting]);

我还this demo表示使用sortList选项应该有效。

但我想知道你是否只在IE中遇到这个问题?我似乎记得IE不喜欢驼峰ID ...可能会尝试将表格ID改为mytable而不是myTable

答案 1 :(得分:-1)

我有同样的错误。在深入了解插件代码并乱搞后,我发现标题单元格的数量与列数不匹配。毕竟这是一个糟糕的HTML,而不是脚本。 tablesorter从那以后运作得很好。