currency sorting

currency sorting

kmk_mohankmk_mohan Posts: 1Questions: 0Answers: 0
edited October 2011 in Plug-ins
Hi,

I am trying to implement currency sorting using datatable. I have data as follows:

[code]
-$1.00
-> empty value
$0.00
-> empty value
-$12.00
$6.00
[/code]

Now, when I sort this, I want results to be as follows:

[code]
-> empty value
-> empty value
-$12.00
-$1.00
$0.00
$6.00
[/code]

But, actual result is:

[code]
-$12.00
-$1.00
-> empty value
$0.00
-> empty value
$6.00
[/code]

Rows with amount values are sorted properly, but rows with empty values remained at same positions.

I am using currency sort plugin as follows:

[code]
jQuery.fn.dataTableExt.oSort['currency_sorting-asc'] = function( x, y ){
x = x.replace( /[^\d\.\-]/g, '' );
y = y.replace( /[^\d\.\-]/g, '' );

/* Remove unnecessary data */
x = x.replace( '
', '' );
y = y.replace( '
', '' );
x = x.replace( '
', '' );
y = y.replace( '
', '' );
x = x.replace( '
', '' );
y = y.replace( '
', '' );
x = x.replace( ' ', '' );
y = y.replace( ' ', '' );
x = x.replace( '', '');
y = y.replace( '', '');
x = x.replace( '\t', '' );
y = y.replace( '\t', '' );
x = x.replace( '\n', '' );
y = y.replace( '\n', '' );
x = x.replace( '\r', '' );
y = y.replace( '\r', '' );
x = x.replace( ',', '' );
y = y.replace( ',', '' );

/* Remove the currency sign */
x = x.substring( 1 );
y = y.substring( 1 );

//x = parseFloat( x );
//y = parseFloat( y );

return x - y;
}
[/code]

I tried uncommenting following lines. But it didn't work.
[code]
//x = parseFloat( x );
//y = parseFloat( y );
[/code]

I tried returning -99999999999999999.00 when x or y is empty. Still, it did'n't work. Can someone please suggest how to resolve this.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    best advice I can give is to echo the values of the rows in your table with console.log (and wrap them in quotes or something so you can see spaces and such) to see what the actual values in your cell are.
This discussion has been closed.