HELP_ME
HELP_ME

Reputation: 2729

Issue with Jquery Table Sorter and columner 00:00

I am having an issue with jquery tablesorter

I have a column that I want treated as integers, but i want it formated like 00:00 Currently, tablesorter will sort like this

this is Decending v

24:30
0:00
1:00
1:00
7:00
10:00

and this is Ascending

10:00
7:00
1:00
1:00
24:30 

How can i get jquery to treat this column like a normal integer or decimal better yet

Upvotes: 1

Views: 133

Answers (1)

ajrawson
ajrawson

Reputation: 1764

I'm going to guess that the tablesorters sort function doesn't see these as integers because of the colon. Tablesorter has an option where you can customize the sort named textExtraction.

You should be able to do something like this:

$('table').tablesorter({
   textExtraction: function (node) {
      return $(node).html().replace(':', '.');
   }
});

This code will replace each colon with a decimal point (you can handle this however you need to) when tablesorter is setting up the sort for your table. The value within the table cell will not change, but the sort value will be setup and stored by tablesorter. Be aware that the code I showed will replace colon's in every cell so you'll need to take that into consideration for the rest of the data in your table.

I use this technique to make columns sort as an integer that have dollar sings included in the table cell. Hope this helps.

Upvotes: 1

Related Questions