jQuery Tablesorter错误

前端之家收集整理的这篇文章主要介绍了jQuery Tablesorter错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
只是更新到最新的tablesorter,看起来像它的破碎或东西。每次我尝试打开我的页面,Firebug说:

table.config.parsers is undefined

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

使用Javascript:

  1. $("#List").tablesorter({
  2. widgets: ['zebra'],headers: {
  3. 4: { sorter: false }
  4. }
  5. })

HTML:

  1. <table id="List" class="tablesort ui-widget-content ui-corner-top">
  2. <thead>
  3. <tr class="ui-widget">
  4. <th>Pa&iacute;s</th>
  5. <th>ISO</th>
  6. <th>ISO3</th>
  7. <th>CODE</th>
  8. <th>&nbsp;</th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. </tbody>
  13. </table>

解决方法

我刚刚遇到这个错误,所以我以为我会发布一个回应,以防其他人有麻烦。

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

当通过AJAX或以其他方式附加或替换现有的表数据与新数据时,这个事件顺序将是必要的:

  1. // populate our table body with rows
  2. $("#myTable tbody").html(json.tbody);
  3.  
  4. // let the sorting plugin know that we made a update
  5. $("#myTable").trigger("update");
  6.  
  7. // set sorting column and direction,this will sort on the first and third column
  8. var sorting = [[2,1],[0,0]];
  9.  
  10. // sort
  11. $("#myTable").trigger("sorton",[sorting]);

“更新”和“排序”事件的组合似乎触发错误。在处理“sorton”事件的时候,DOM没有被分配给table.config.parsers – 因此是错误的。

修复是在1毫秒超时中包装“sorton”事件处理。

将jquery.tablesorter.js(line〜803)中的现有“sorton”绑定替换为以下内容

  1. }).bind("sorton",function (e,list) {
  2. var me = this;
  3. setTimeout(function () {
  4. $(this).trigger("sortStart");
  5. config.sortList = list;
  6. // update and store the sortlist
  7. var sortList = config.sortList;
  8. // update header count index
  9. updateHeaderSortCount(me,sortList);
  10. // set css for headers
  11. setHeadersCss(me,$headers,sortList,sortCSS);
  12. // sort the table and append it to the dom
  13. appendToTable(me,multisort(me,cache));
  14. },1);

tablesorter()真的是一个方便的插件。感谢基督徒释放它。

猜你在找的jQuery相关文章