Table Sorter - Problem sorting numbers with comma seperators

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Table Sorter - Problem sorting numbers with comma seperators

elitz

Using table sorter for first time. Working fine expect for columns
containing large numbers having comma seperators (e.g. 4,500,000).
It's not sorting these columns as numerics regardless of what type of
sort parser i seem to specify. (integer, numeric). In the same table i
have a few currency columns with leading $ characters and embedded
commas and these work fine...but the numbers that do not have leading
dollar signs are not sorting correctly...they are sorting as text,
there the number 200 comes before 1,400,000 for example. Any help
appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "jQuery Plugins" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/jquery-plugins?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Table Sorter - Problem sorting numbers with comma seperators

felipe fernandez

Define  a parser :   

$.tablesorter.addParser({

  id: "n_euro",
  is: function(s) {
  // return false so this parser is not auto detected
  return false;
  },
  format: function(s) {
  s = s.replace(/\./g,"");
  s = s.replace(/\,/g,".");
  return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));
  },
  type: 'numeric'
  }); 


And 

 $("#datos") 
  .tablesorter({
...

headers: {column: {sorter: n_euro}}
...

});


2008/12/7 elitz <[hidden email]>

Using table sorter for first time. Working fine expect for columns
containing large numbers having comma seperators (e.g. 4,500,000).
It's not sorting these columns as numerics regardless of what type of
sort parser i seem to specify. (integer, numeric). In the same table i
have a few currency columns with leading $ characters and embedded
commas and these work fine...but the numbers that do not have leading
dollar signs are not sorting correctly...they are sorting as text,
there the number 200 comes before 1,400,000 for example. Any help
appreciated.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "jQuery Plugins" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/jquery-plugins?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Table Sorter - Problem sorting numbers with comma seperators

Ryan-145
In reply to this post by elitz

Hi

I also added a parser. Here is mine.

ts.addParser({
        id: "digit",
        is: function(s,table) {
            var c = table.config;
            return $.tablesorter.isDigit(s,c);
        },
        format: function(s) {
               if (s.match(',')) {
                    s = s.replace(/\,/, '');
               }
               if (s.match('<')) {
                    s = s.replace(/\</, '');
               }
               if (s.match(' ')) {
                    s = s.replace(/\ /, '');
               }
            return $.tablesorter.formatFloat(s);
        },
        type: "numeric"
    });

------------------------------

In my document read function for a table i wanted sorted i added this:

$("#performanceTable").tablesorter({
            indexing: true,
            widthFixed: true,
            sortInitialOrder: 'desc',
            debug: false,
            widgets: ['zebra'],
            textExtraction: 'complex',
            headers: {
                0: {
                    sorter: false
                }
                2: {
                    sorter: 'digit'
                },
                3: {
                    sorter: 'digit'
                },
                4: {
                    sorter: 'digit'
                }
                ,
                5: {
                    sorter: 'digit'
                }
                ,
                6: {
                    sorter: 'digit'
                }
                ,
                7: {
                    sorter: 'digit'
                }
                ,
                8: {
                    sorter: 'digit'
                }
            }
        });

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "jQuery Plugins" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/jquery-plugins?hl=en
-~----------~----~----~----~------~----~------~--~---