SortTable containing plus and minus sign
SortTable containing plus and minus sign
Hi, i have a table contains data that has + sign if it is a positive data and - sign if it is a negative, but when i sort the table it is not displaying correctly. e.g. after sort the column becomes the following:
-0.03
-0.025
+0.19
+0.11
Is there anyway to work around this? Thank you very much
-0.03
-0.025
+0.19
+0.11
Is there anyway to work around this? Thank you very much
This discussion has been closed.
Replies
Use it something like this:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aoColumnDefs": [
{ "sType": "signed-num", "aTargets": [ 3 ] }
]
} );
} );
[/code]
Allan
125 000,00 (whitscpace between numers failed)
+3,59% (percentage problem)
-3,59% (percentage problem)
+3,55 (plus char problem)
-2,55 (minus char problem)
I was already using the dataTables.numericComma.js plugin which I got some help to rewrite a little using a regular expression instead:
Here is the script changes I use now that works for me:
[code]
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/, "." ).replace( /[^\d\-]/g, "" );
var y = (b == "-") ? 0 : b.replace( /,/, "." ).replace( /[^\d\-]/g, "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/, "." ).replace( /[^\d\-]/g, "" );
var y = (b == "-") ? 0 : b.replace( /,/, "." ).replace( /[^\d\-]/g, "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]