Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery tablesorter plugin secondary "hidden" sorting

Tags:

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.

like image 382
Pelle Avatar asked Mar 03 '12 22:03

Pelle


People also ask

How to sort a table using jQuery?

How to start using jQuery? More in this category... tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes and any server-side code. tablesorter can successfully parse and sort many types of data including linked data in a cell.

What is tablesorter in jQuery?

tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes and any server-side code. tablesorter can successfully parse and sort many types of data including linked data in a cell.

What is This list in the tablesorter plugin?

This list contains DOM elements (not jQuery objects of each table header cell like the $headers variable) and is how the original version of tablesorter stored these objects. It is not used in the current version of tablesorter, and is only left in place for backwards compatibility with widgets written for the original tablesorter plugin.

What version of jQuery do I need to enable secondary sorting?

Support secondary "hidden" sorting (e.g., maintain alphabetical sort when sorting on other criteria) Works with jQuery 1.2.6+ (jQuery 1.4.1+ needed with some widgets). Works with jQuery 1.9+ ($.browser.msie was removed; needed in the original version). TIP!


1 Answers

Just using the textExtraction function. Set data-sort-value on your TDs. Defaults to normal text if it's not present.

$(".sort-table").tablesorter({     textExtraction: function(node) {         var attr = $(node).attr('data-sort-value');         if (typeof attr !== 'undefined' && attr !== false) {             return attr;         }         return $(node).text();      }  });  
like image 57
Charles Avatar answered Oct 05 '22 23:10

Charles