首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >jQuery表排序错误

jQuery表排序错误
EN

Stack Overflow用户
提问于 2010-12-16 19:09:54
回答 7查看 16.3K关注 0票数 16

刚刚更新到最新的表排序,看起来像是坏了还是怎么的。每次我试图打开我的页面时,Firebug都会说:

table.config.parsers未定义

它破坏了我所有的Javascript。如果我恢复表排序版本,它会工作得很好。

Javascript:

代码语言:javascript
复制
$("#List").tablesorter({ 
    widgets: ['zebra'],
    headers: { 
        4: { sorter: false }
    }
})

HTML:

代码语言:javascript
复制
<table id="List" class="tablesort ui-widget-content ui-corner-top">
    <thead>
      <tr class="ui-widget">
          <th>Pa&iacute;s</th>
          <th>ISO</th>
          <th>ISO3</th>
          <th>CODE</th>
          <th>&nbsp;</th>
      </tr>
    </thead>
    <tbody>
    </tbody>
</table>
EN

回答 7

Stack Overflow用户

发布于 2011-07-30 01:38:48

尽管上面的答案没有提到这一点,但我能够通过首先实例化tablesorter()然后触发排序请求来复制错误。

当通过AJAX或其他方式使用新数据追加或替换现有表数据时,此事件顺序是必需的:

代码语言:javascript
复制
// 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“绑定替换为以下内容:

代码语言:javascript
复制
}).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发布了它。

票数 14
EN

Stack Overflow用户

发布于 2011-03-27 05:46:23

有点晚了,但这是因为<tbody>中有一个空的/没有<tr>元素,并且它至少需要一个<tr>

票数 13
EN

Stack Overflow用户

发布于 2015-03-23 14:27:47

我尝试了上面的一些答案,但它们并不是对我们使用tablesorter的每个页面都有帮助。我认为错误的主要原因是c=sortListi未定义,要么是因为我们有一个空的TR,要么是因为我们没有与TH相同数量的TD。

我有8个/ TD以防我有表格数据,还有8个&单个TD以防我没有什么可显示的。我设法检查是否没有表数据,然后不调用tablesorter对不存在的特定列进行排序。这就起到了作用。可能会对有类似情况的人有所帮助

代码语言:javascript
复制
if(tableData.length != 0){
  $("#myid").tablesorter( {sortList: [[2,0]]});
}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4460107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档