jQuery 表排序器错误
刚刚更新到最新的表格排序器,看起来像是坏了之类的。每次我尝试打开我的页面时,Firebug 都会说:
table.config.parsers 未定义
它只会破坏我所有的 Javascript。 如果我恢复 tablesorter 版本,它会正常工作。
JavaScript:
$("#List").tablesorter({
widgets: ['zebra'],
headers: {
4: { sorter: false }
}
})
HTML:
<table id="List" class="tablesort ui-widget-content ui-corner-top">
<thead>
<tr class="ui-widget">
<th>País</th>
<th>ISO</th>
<th>ISO3</th>
<th>CODE</th>
<th> </th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Just updated to the latest tablesorter and looks like its broken or something. Everytime i try to open my page, Firebug says:
table.config.parsers is undefined
And it just breaks all of my Javascript.
If I revert the tablesorter version, it will work fine.
Javascript:
$("#List").tablesorter({
widgets: ['zebra'],
headers: {
4: { sorter: false }
}
})
HTML:
<table id="List" class="tablesort ui-widget-content ui-corner-top">
<thead>
<tr class="ui-widget">
<th>País</th>
<th>ISO</th>
<th>ISO3</th>
<th>CODE</th>
<th> </th>
</tr>
</thead>
<tbody>
</tbody>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
问题似乎是,如果通过 JavaScript 填充表格,除非浏览器显示了新内容,否则表格排序器不会找到新内容。
在 setTimeout() 例程中触发表排序器为我消除了该错误。
The problem seems to be that if the table is filled via JavaScript the tablesorter doesn't find the new content unless the browser has displayed the new content.
Firing the tablesorter inside a setTimeout() routine removed that error for me.
另一个答案,以防万一有人遇到与我相同的情况。显然,表排序器有时喜欢在空
内有匹配数量的空
元素(与标头元素相同)。我的部分示例如下
Another answer just in case anyone ever runs into the same scenario I did. Apparently table sorter sometimes likes to have a matching number of empty
<td>
elements (the same as your header elements) inside the empty<tr>
. My partial example is below请注意,tablesorter AJAX 示例仅演示了附加新行的场景 到现有的。当动态清空表并用新行重新填充表时,会出现上述错误。
添加一个空行,
其
数量与标头中
的数量相同,可以消除该错误,但会引入另一个错误:表被清空并用实际行重新填充,新行将附加到旧行。
作为修改 tablesorter 源代码的替代方法,请尝试以下调用顺序:
Note that the tablesorter AJAX example only demonstrates a scenario in which new rows are appended to the existing ones. When the table is dynamically emptied and refilled with new rows, the above error surfaces.
Adding an empty row
with the same number of
<td>
s as the number of<th>
s in the header removes the error but introduces another one: after the table is emptied and refilled with real rows, the new rows are appended to the old ones.As an alternative to modifying the tablesorter source code, try the following invocation sequence:
我遇到了一种情况,当我收到错误消息时没有专门更新 tablesorter,只是因为 tfoot 元素中的列数与 thead 中的列数不匹配和 tbody,所以 tablesorter 插件对此感到困惑。
人们可能会在更新表排序器的同一天犯这个错误。我想我也应该在这个主题中分享这个技巧,以供将来参考。
I encountered a case when I got that error message without specifically updating tablesorter, but just because the numbers of columns in the
tfoot
element was not matching the number of columns in thethead
andtbody
, so the tablesorter plugin go confused over that.One may make that mistake on the same day as updating tablesorter. I thought I'd share this trick too in this subject, for future reference.
尽管上面的答案没有提到它,但我能够通过首先实例化 tablesorter() 然后触发排序请求来复制错误。
当通过 AJAX 或其他方式用新数据附加或替换现有表数据时,这种事件顺序是必要的:
“update”和“sorton”事件的组合似乎触发了错误。当处理“sorton”事件时,DOM 尚未分配给 table.config.parsers - 因此出现错误。
修复方法是将“sorton”事件处理封装在 1 毫秒超时内。
将 jquery.tablesorter.js(第 803 行)中现有的“sorton”绑定替换为以下内容:
tablesorter() 是确实是一个方便的插件。感谢克里斯蒂安发布它。
Although the above answer doesn't mention it, I was able to replicate the error by first instantiating tablesorter() and then triggering a sort request.
This order of events would be necessary when appending or replacing existing table data with new data via AJAX or otherwise like so:
The combination of the "update" and the "sorton" event seems to be triggering the error. By the time the "sorton" event is handled the DOM hasn't been assigned the table.config.parsers - thus the error.
The fix is to wrap the "sorton" event handling in a 1 millisecond timeout.
Replace the existing "sorton" bind in jquery.tablesorter.js (line ~803) with the following:
tablesorter() is really a handy plugin. Thanks to Christian for releasing it.
有点晚了,但是,这是因为
中有一个空/没有
元素,并且它需要至少一个
;
。Bit late but, it's because you have an empty/no
<tr>
element in the<tbody>
, and it expects at least one<tr>
.我尝试了上面的一些答案,但它们对我们使用表排序器的每个页面都没有帮助。我认为错误的主要原因是 c=sortList[i][0] 未定义,要么因为我们有一个空 TR,要么我们的 TD 数量与 TH 数量不同。
如果我有表格数据,我有 8 TH/TD 和 8 TH & TD。单身 TD,以防我没有什么可展示的。我设法检查我是否没有表数据,然后不调用 tablesorter 对不存在的特定列进行排序。这成功了。可能会帮助有类似情况的人
I tried some of the answers above but they didn't help in every page we were using tablesorter. Primary reason I figured for error is that c=sortList[i][0] is undefined either because we have an empty TR or we don't same number of TD as that of TH.
I had 8 TH/TD in case I have table data and 8 TH & single TD in case I have nothing to show. I managed to check if I have no table data then don't call tablesorter to sort on specific columns which doesn't exist. This did the trick. Might help someone with similar scenario