jquery-pluginstablesorter

jQuery tablesorter plugin secondary "hidden" sorting


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 like to sort this column as if it were a date column. As I understand it, it is possible to sort the column with some other 'hidden' value, but I just can't seem to find the documentation for that feature. Any help out there?

Update

This fork http://mottie.github.com/tablesorter/docs/index.html of the tablesorter had just what I needed; the ability to store the value to sort by in an attribute, worked really great.


Solution

  • 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' }
        }
      });
    
    });