currency sorting
currency sorting
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.
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.
This discussion has been closed.
Replies