i have problem with jQuery tablesorter and numbers like 12 345 678,91
$(document).ready(function() {
$.tablesorter.addParser({
id: 'thousands',
is: function(s) {
return false;
},
format: function(s) {
return s.replace(' ','').replace(/,/g,'');
},
type: 'numeric'
});
$("#tablesorter").tablesorter({
headers: {
3: { sorter:'thousands' },
4: { sorter:'thousands' },
5: { sorter:'thousands' }
}
});
});
output filter:
-1 295,76
-331,2
-330,01
-290
0
3 986 495,06
1 942 503,09
0
0
When i replace this: s.replace(‘ ‘,”).replace(/,/g,”);
by this : s.replace(new RegExp(/[^0-9/A-Za-z. ]/g),””);
…even worse than it was.
any ideas?
The parser isn’t replacing all of the spaces; using
replace(' ','')will only replace the first space. Also, the comma should be replaced with a decimal point since it indicates a fraction. So, try this (demo):