Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma formatted currency doesn't sort. #43

Open
RyanPaiva56 opened this issue Oct 3, 2014 · 3 comments · May be fixed by #56
Open

Comma formatted currency doesn't sort. #43

RyanPaiva56 opened this issue Oct 3, 2014 · 3 comments · May be fixed by #56

Comments

@RyanPaiva56
Copy link

I've got some values like
$955,555
$933,000,000

And it sorts in that order, even though the second number is larger, but the first number appears larger if you dont count what's after the comma. How do I resolve this?

@RyanPaiva56
Copy link
Author

I found a few examples on SO like this:

http://stackoverflow.com/questions/13401316/tablesorter-sorting-number-with-commas-in-them

But making any change to the table sorter through this method:

$("table").tablesorter({

Breaks the script and only lets me sort once and then it's stuck and wont react to me clicking on the headers. Console debugger has no output. Any ideas?

Edit: as a clarificaiton, it will let me sort still, but ALL of my columns will only sort from largest to smallest.
Full code:

$(document).ready(function() 
    { 
        $("#month-data").tablesorter();
    } 
); 

// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'thousands',
    is: function(s) { 
        // return false so this parser is not auto detected 
        return false; 
    }, 
    format: function(s) {
        // format your data for normalization 
        return s.replace('$','').replace(/,/g,'');
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 

$(function() {
    $("table").tablesorter({
        headers: {
            8: {//zero-based column index
                sorter:'thousands'
            }
        }
    });
});

@dougjohnston
Copy link

@golevel You don't need to add a new parser, just to ignore commas when dealing with currencies. See the above pull request for the fix.

@rokam
Copy link

rokam commented Nov 13, 2014

With my pull request you can set the decimal and thousand character. The default is comma, so it might work without any problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants