我想用jQuery插件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>
所以你可以看到我的表是空的,只有一个标题。所以我用空单元格初始化表排序:
$("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>
你知道为什么我会得到这个插件,以及怎样才能让插件再次工作吗?
Thx
发布于 2012-01-18 15:34:56
您需要在表中包含数据,然后才能对其调用sortList方法。这是因为您在此方法中应用了索引,如果不存在任何数据,则不会找到任何记录,并且会抛出"Cannot read property '0‘of undefined“错误。
发布于 2012-10-31 00:35:40
当有一个空表时,不适合使用tablesorter,所以你可以使用这个条件:
if ($("table#stats tbody tr").length > 0)
$(this).tablesorter({ sortList: [[0,0]]});
发布于 2014-07-25 10:45:42
我不能让任何这些工作,所以我设置了一个超时初始化为表排序…
setTimeout(function() {$('table').tablesorter();}, 10000);
https://stackoverflow.com/questions/8878945
复制相似问题