I am trying to sort data in a table using the tablesorting plugin, but the data has commas (,) as a delimiter, so they are not sorted correctly. I think it treats the number as a string. With google, I found some codes, but they do not work for me. Here is what I have tried so far.
$(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"
});
$("#myTable").tablesorter({
widgets : ['zebra']
});
});
Please tell me what I'm doing wrong.
I also gave a class <th width="62" class="{sorter: 'fancyNumber'}">column</th>in a column.
source
share