sort numbers with the format #,###,###.##
sort numbers with the format #,###,###.##
In my country the convention for expressing numbers is to use the . as a thousands separator and the , as the decimal separator. an example of this would be: 25.367,212 I have been unable to make datatables.js sort any column that uses this formatting.
I am using the following extensions:
[code]
//formatted number sort
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function (a) {
a = (a === "-" || a === "") ? 0 : a.replace(/[^\d\-\.]/g, "");
return parseFloat(a);
},
"formatted-num-asc": function (a, b) {
return a - b;
},
"formatted-num-desc": function (a, b) {
return b - a;
}
});
//formatted number autodetection
jQuery.fn.dataTableExt.aTypes.unshift(
function (sData) {
var deformatted = sData.replace(/[^\d\-\.\/a-zA-Z]/g, '');
if ($.isNumeric(deformatted) || deformatted === "-") {
return 'formatted-num';
}
return null;
}
);
[/code]
has anyone been able to solve tis problem?
I am using the following extensions:
[code]
//formatted number sort
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function (a) {
a = (a === "-" || a === "") ? 0 : a.replace(/[^\d\-\.]/g, "");
return parseFloat(a);
},
"formatted-num-asc": function (a, b) {
return a - b;
},
"formatted-num-desc": function (a, b) {
return b - a;
}
});
//formatted number autodetection
jQuery.fn.dataTableExt.aTypes.unshift(
function (sData) {
var deformatted = sData.replace(/[^\d\-\.\/a-zA-Z]/g, '');
if ($.isNumeric(deformatted) || deformatted === "-") {
return 'formatted-num';
}
return null;
}
);
[/code]
has anyone been able to solve tis problem?
This discussion has been closed.
Replies
Allan
im guessing it would replace this part:
a.replace(/[^\d\-\.]/g, "")
Allan
http://stackoverflow.com/questions/20336091/sort-numbers-with-the-format-with-datatables-js