【发布时间】:2012-01-16 10:51:07
【问题描述】:
我想用 jQuery Plugin TableSorter 对我的表进行排序。所以我得到了这张桌子:
<table id="stats" class="zebra-striped">
<thead>
<tr>
<th>Date</th>
<th>Annonce</th>
<th>Support</th>
<th>Nb Assoc.</th>
<th>Nb Transfo.</th>
<th>Cout</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
所以你可以看到我的表是空的,只有标题。所以我用空单元格初始化tablesorter:
$("table#stats").tablesorter({ sortList: [[0,0]]});
我立即收到此错误:
jquery.tablesorter.min.js:4 Uncaught TypeError: Cannot read property '0' of undefined
仅供参考,我的 js 已加载:
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>
<script src="js/bootstrap-dropdown.js"></script>
<script src="js/bootstrap-scrollspy.js"></script>
<script src="js/jquery.tablesorter.min.js"></script>
知道为什么我会得到这个以及如何使插件再次工作吗?
谢谢
【问题讨论】:
-
听起来你的tablesorter函数没有正确加载,你能检查一下页面中加载的javascript文件吗?
-
@JoJa:刚刚检查过。似乎还好。我编辑帖子以包含它;)
-
如果你放了一个空的
里面有空的 ? 根据plugin documentation,我可以用一个空表来初始化它:(在您包含的文档中,他们首先用数据填充表格,然后调用该 sortList 方法。
标签: jquery jquery-plugins tablesorter