Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tablesorter sorting number with commas in them

I am having issues using tablesorter plugin for currencies with a , in them e.g.: 9,789,000.00 etc.

Does anyone know of a work around for this?

Pls dont suggest me the other libraries.

like image 230
Haran Murthy Avatar asked Dec 16 '25 23:12

Haran Murthy


1 Answers

Tablesorter allows you to define "custom parsers" for things like this.

// 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: {
            6: {//zero-based column index
                sorter:'thousands'
            }
        }
    });
});

You may have to tweak the format function.

Also try to search here on the page, the subject has been answered discussed plenty of times like here

like image 76
Jacta Avatar answered Dec 19 '25 13:12

Jacta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!