如果有类,jQuery Tablesorter不对列进行排序

Cam*_*ron 2 jquery tablesorter

我目前使用以下内容告诉我的表不使用jquery Tablesorter插件对某些列进行排序:

$(".uiGridContent table").tablesorter({
        sortList: [[1, 0]],
        headers: {
            0: { sorter: false },
            5: { sorter: false },
            6: { sorter: false }
        }
    });
Run Code Online (Sandbox Code Playgroud)

问题是在我的应用程序上,用户可以添加和删除列,因此订单可以更改,因此我当前的代码不是一个可行的解决方案.如果我在列上放一个类,我不想排序,例如<col class="nosort" />我怎么能这样做,所以它不排序那些列?

因为我正在使用<col />我尝试了以下内容:

$filter_ignore = $("col.nosort").closest("th").index();

    $(".uiGridContent table").tablesorter({
        sortList: [[1, 0]],
        headers: {
            $filter_ignore: {
                sorter: false
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

但是不起作用:/

我想我需要某种循环来找到所有这些带有柱子的柱子!这是我的表的一个例子:

<table>
 <colgroup>
  <col class="nosort" />
  <col />
 </colgroup>
  <thead>
   <tr>
    <th scope="col">a</th>
    <th scope="col">b</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td scope="col">a</td>
    <td scope="col">b</td>
   </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

谢谢

Cam*_*ron 11

function setupTablesorter() {
    $('table.tablesorter').each(function (i, e) {
        var myHeaders = {}
        $(this).find('th.nosort').each(function (i, e) {
            myHeaders[$(this).index()] = { sorter: false };
        });

        $(this).tablesorter({ widgets: ['zebra'], headers: myHeaders });
    });    
}
Run Code Online (Sandbox Code Playgroud)

这似乎效果最好!