jQuery tablesorter plugin secondary “hidden” sorting

后端 未结 6 1805
粉色の甜心
粉色の甜心 2021-02-05 06:24

I\'m using the jQuery tablesorter plugin and I have a column that contains name of month and year like this

April, 1975
January, 2001

I would l

6条回答
  •  既然无缘
    2021-02-05 06:49

    I have a fork of tablesorter that allows you to write a parser that can extract data attributes from the table cell as well as assign specific textExtraction for each column.

    $(function(){
    
      $.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' 
      }); 
    
      $('table').tablesorter({ 
        headers : { 
          0 : { sorter: 'myParser' }
        }
      });
    
    });
    

提交回复
热议问题