I am attempting to add a custom fancyNumber parser to tablesorter via here.
However when I add the code to my page as follows:
jQuery(document).ready( function() {
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"
});
} );
I then set my table headers as follows:
'<th class="{\'sorter\': \'fancyNumber\'}"><strong>Calls</strong></th>' +
I have to escape the single quotes as my table headers are wrapped up in a JavaScript variable.
However this does not work and my numbers with commas are still being sorted incorrectly:
Calls
783
660
642,826
613
603,321
I wonder if the metadata plugin was loaded. The sorter being set in the header as shown above requires the plugin.
Personally, I think a better method would be to set the sorter in the
headersoption:Here is a demo I set up to show that it works.