jQuery tablesorter - 每列两个排序选项

问题描述

问题与此处的示例有关:https://mottie.github.io/tablesorter/docs/example-parsers.html

我想在一列上做两个排序选项。 假设我想在表格上方制作单选按钮。 一个按钮是按名称对成绩进行排序,另一个按钮是按成绩对成绩进行排序。

我怎么能这样做?我尝试了各种解决方案,但没有一个能如我所愿。

这是我的最后一个代码,但仅适用于第一个选择的排序类型。要按另一种类型排序,我必须刷新。

function btnpressed(){
  if (document.getElementById("byName").checked === true){
    $(function() {
      $("table").tablesorter({
        theme: 'blue'
      });
    });
  } else if (document.getElementById("byGrade").checked === true){
    // add parser through the tablesorter addParser method
    $.tablesorter.addParser({
      // set a unique id
      id: 'grades',is: function(s,table,cell,$cell) {
        // return false so this parser is not auto detected
        return false;
      },format: function(s,cellIndex) {
        // format your data for normalization
        return s.toLowerCase()
          .replace(/good/,2)
          .replace(/medium/,1)
          .replace(/bad/,0);
      },// set type,either numeric or text
      type: 'numeric'
    });

    $(function() {
      $("table").tablesorter({
        theme: 'blue'
        // "sorter-grades" added as a class name in the HTML (new in v2.0.11)
        // or un-comment out the option below
        //,headers: { 6: { sorter: 'grades' } }
      });

    });
  }
}
@H_404_10@

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)