sorting is not working if we have data with comma , negative/positive values and two decimal values
sorting is not working if we have data with comma , negative/positive values and two decimal values
nandrai
Posts: 26Questions: 0Answers: 0
[quote]
the data is when sorted as desc
-2,598.00
-3,493.70
-350.00
-36.00
-435.75
-8,200.00
0.00
0.00
17,444.00
27,200.00
736.75
[/quote]
and the code is that i used is
[code]
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
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( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
/* Table initialisation */
$(document).ready( function() {
$('#myTable').dataTable( {
"sPaginationType": "full_numbers",
"aoColumns": [
null,
null,
null,
null,
null,
{ "sType": "numeric-comma" },
null,
null
]
}
);
} )
[/code]
the data is when sorted as desc
-2,598.00
-3,493.70
-350.00
-36.00
-435.75
-8,200.00
0.00
0.00
17,444.00
27,200.00
736.75
[/quote]
and the code is that i used is
[code]
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
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( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
/* Table initialisation */
$(document).ready( function() {
$('#myTable').dataTable( {
"sPaginationType": "full_numbers",
"aoColumns": [
null,
null,
null,
null,
null,
{ "sType": "numeric-comma" },
null,
null
]
}
);
} )
[/code]
This discussion has been closed.