只是更新到最新的tablesorter,看起来像它的破碎或东西。每次我尝试打开我的页面,Firebug说:
table.config.parsers is undefined
它只是打破了我所有的Javascript。
如果我恢复了tablesorter版本,它可以正常工作。
使用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>
解决方法
我刚刚遇到这个错误,所以我以为我会发布一个回应,以防其他人有麻烦。
虽然上面的答案没有提到,但我能够通过首先实例化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]);
“更新”和“排序”事件的组合似乎触发错误。在处理“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,cache));
- },1);
tablesorter()真的是一个方便的插件。感谢基督徒释放它。