【问题标题】:Jquery - sort based on attribute for all columnsJquery - 基于所有列的属性排序
【发布时间】:2014-07-09 21:09:54
【问题描述】:

我正在使用 jquery 表格排序插件。

表列是根据sql查询生成的。

如何根据属性值进行排序(升序和降序)。

注意:我不喜欢下面的代码,因为表格列是生成多个(有时是 50 列),所以我需要根据相同的属性名称对所有列进行排序。

$.tablesorter.addParser({ 
    // set a unique id 
    id: 'myParser', 
    is: function(s) { 
      // return false so this parser is not auto detected 
      return false; 
    }, 
    format: function(s, table, cell, cellIndex) { 
      // get data attributes from $(cell).attr('data-something');
      // check specific column using cellIndex
      return $(cell).attr('data-something');
    }, 
    // set type, either numeric or text 
    type: 'text' 
  });

【问题讨论】:

    标签: jquery html tablesorter


    【解决方案1】:

    如果您使用我的 tablesorter 分支,您可以将 textAttribute option 设置为您在表格中使用的任何数据属性。默认设置为data-text:

    <td data-text="1">First</td>
    

    然后将使用来自data-text 的值而不是“First”对该单元格进行排序。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多