Sorting Numeric String with $, comma and dot
Sorting Numeric String with $, comma and dot
tekie
Posts: 1Questions: 1Answers: 0
i have a string column with dollar sign($) separated with commas and have dot for decimal numbers. Currently am using datatable V 1.8. but the sorting is working as string even after i have used formatted-num plugin.
$100.00
$124.00
$2,345.00
$2.51
$230.00
$250.00
This is how it is sorting now.
Below is the code i am using in my javascript.
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;
}
} );
searchResuluts= $("#summarResult").dataTable({
aoColumnDefs : [
{"sType" : "formatted-num", "aTargets": [5] }
]
)};
Could you please help me on how i can get sorted order in a proper way.Your help is really appriciated. Thank you.
This discussion has been closed.
Answers
Hi @tekie ,
That's an old version, it would be worth updating as these types are handing internally without any additional code. If you can't update, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin