刚刚更新到最新的表排序,看起来像是坏了还是怎么的。每次我试图打开我的页面时,Firebug都会说:
table.config.parsers未定义
它破坏了我所有的Javascript。如果我恢复表排序版本,它会工作得很好。
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>
发布于 2011-07-30 01:38:48
尽管上面的答案没有提到这一点,但我能够通过首先实例化tablesorter()然后触发排序请求来复制错误。
当通过AJAX或其他方式使用新数据追加或替换现有表数据时,此事件顺序是必需的:
// populate our table body with rows
$("#myTable tbody").html(json.tbody);
// let the sorting plugin know that we made a update
$("#myTable").trigger("update");
// set sorting column and direction, this will sort on the first and third column
var sorting = [[2,1],[0,0]];
// sort
$("#myTable").trigger("sorton",[sorting]);
"update“和"sorton”事件的组合似乎触发了错误。当"sorton“事件被处理时,DOM还没有被分配table.config.parsers -因此出现了错误。
修复方法是将"sorton“事件处理包装在1毫秒的超时中。
将jquery.tablesorter.js (第~803行)中现有的"sorton“绑定替换为以下内容:
}).bind("sorton", function (e, list) {
var me = this;
setTimeout(function () {
$(this).trigger("sortStart");
config.sortList = list;
// update and store the sortlist
var sortList = config.sortList;
// update header count index
updateHeaderSortCount(me, sortList);
// set css for headers
setHeadersCss(me, $headers, sortList, sortCSS);
// sort the table and append it to the dom
appendToTable(me, multisort(me, sortList, cache));
}, 1);
tablesorter()确实是一个很方便的插件。感谢Christian发布了它。
发布于 2011-03-27 05:46:23
有点晚了,但这是因为<tbody>
中有一个空的/没有<tr>
元素,并且它至少需要一个<tr>
。
发布于 2015-03-23 14:27:47
我尝试了上面的一些答案,但它们并不是对我们使用tablesorter的每个页面都有帮助。我认为错误的主要原因是c=sortListi未定义,要么是因为我们有一个空的TR,要么是因为我们没有与TH相同数量的TD。
我有8个/ TD以防我有表格数据,还有8个&单个TD以防我没有什么可显示的。我设法检查是否没有表数据,然后不调用tablesorter对不存在的特定列进行排序。这就起到了作用。可能会对有类似情况的人有所帮助
if(tableData.length != 0){
$("#myid").tablesorter( {sortList: [[2,0]]});
}
https://stackoverflow.com/questions/4460107
复制相似问题