jQuery Tablesorter错误

ale*_*dre 16 jquery tablesorter

刚更新到最新的tablesorter,看起来像它破碎或什么的.每当我试图打开我的页面时,Firebug说:

table.config.parsers未定义

它只是打破了我的所有Javascript.如果我恢复tablesorter版本,它将正常工作.

使用Javascript:

$("#List").tablesorter({ 
    widgets: ['zebra'],
    headers: { 
        4: { sorter: false }
    }
})
Run Code Online (Sandbox Code Playgroud)

HTML:

<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>
Run Code Online (Sandbox Code Playgroud)

jro*_*b00 14

我刚刚遇到这个错误所以我想我会发布一个回复以防其他人以后遇到问题.

虽然上面的答案没有提到它,但我能够通过首先实例化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]);
Run Code Online (Sandbox Code Playgroud)

"更新"和"排序"事件的组合似乎触发了错误.到处理"sorton"事件时,尚未为DOM分配table.config.parsers - 因此错误.

修复是在1毫秒超时中包装"sorton"事件处理.

用以下内容替换jquery.tablesorter.js(line~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);
Run Code Online (Sandbox Code Playgroud)

tablesorter()实际上是一个方便的插件.感谢Christian发布它.


小智 13

有点迟了,这是因为你有一个空/无<tr>元素<tbody>,它至少有一个<tr>.

  • 我们设法绕过它的一种方式是通过与虚拟出发的<tr>不管表中是否有任何数据或没有,然后通过对文档加载JS隐藏它. (3认同)