Chris
Chris

Reputation: 4364

jQuery tablesorter sorting comma separated numbers

I'm using the jQuery Tablesorter 2.0 (http://tablesorter.com/docs/). Sorting numbers is working fine, but as soon as I add

number_format($count);

to my code, the sorting is not working anymore. It sorts like this:

810,208 -> 7,671,897 -> 2,329,439

instead of

7,671,897 -> 2,329,439 -> 810,208

Any way to fix this? I need the comma separated number for better reading. Thanks

Upvotes: 3

Views: 5448

Answers (1)

hannebaumsaway
hannebaumsaway

Reputation: 2734

http://www.christianmontoya.com/2008/11/14/extending-jquery-tablesorter-to-support-comma-delimited-numbers/

jQuery.tablesorter.addParser({
  id: "fancyNumber",
  is: function(s) {
    return /^[0-9]?[0-9,\.]*$/.test(s);
  },
  format: function(s) {
    return jQuery.tablesorter.formatFloat( s.replace(/,/g,'') );
  },
  type: "numeric"
});

Upvotes: 11

Related Questions