【问题标题】:Only one column sorting using JQuery Table Sorter Plug-In仅使用 JQuery Table Sorter Plug-In 进行一列排序
【发布时间】:2015-09-03 09:39:56
【问题描述】:

我正在使用 jQuery 的 tablesorter 插件在客户端对我的 gridview 进行排序。但这是问题所在,我必须使该排序选项仅适用于一列。 (gridview中的列号为7)

 $("#<%=gvResults.ClientID%>").tablesorter();

我们如何使用表格排序器插件来实现它。大家有什么建议

【问题讨论】:

    标签: jquery asp.net sorting gridview tablesorter


    【解决方案1】:

    如果您知道将启用排序的列索引,则将headers 选项设置如下:

    $(function(){
      $('table').tablesorter({
        headers : {
          // zero-based column index
          0 : { sorter: false },
          1 : { sorter: false },
          2 : { sorter: false },
          3 : { sorter: false },
          4 : { sorter: false },
          5 : { sorter: false }
        }
      });
    });
    

    上面的代码适用于原始的tablesorter和我的fork of tablesorter

    如果你碰巧使用了我的 tablesorter 分支,那么你可以在标题中添加类名:

    <th class="sorter-false">column 1</th>
    <th class="sorter-false">column 2</th>
    <th class="sorter-false">column 3</th>
    <!-- etc -->
    <th>column 7</th>
    

    然后在没有任何额外选项的情况下初始化 tablesorter:

    $(function(){
      $('table').tablesorter();
    });
    

    【讨论】:

      【解决方案2】:

      从你不想排序的标题中删除类“标题”,例如,如果它只是你想要排序的第七行,写

      $('.header').not('.header:nth-child(7)').removeClass('header');
      

      通过添加这个 html 在开始时运行它:

      <script>
          $(document).ready(function()
          {
              $('.header').not('.header:nth-child(7)').removeClass('header');
              $('.header').not('.header:nth-child(7)').click(function(event)
              {
                  event.preventDefault();
              });
              $('.headerSortDown').removeClass('headerSortDown');  // fixes a bug
              $('.headerSortUp').removeClass('headerSortUp');  // fixes a bug
          });
      </script>
      

      【讨论】:

      • 此代码仅在tablesorter(原始版本)初始化后才能工作。
      猜你喜欢
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 2019-11-04
      • 2019-02-08
      • 1970-01-01
      相关资源
      最近更新 更多