Sorting & Filtering
Sorting & Filtering
Hello All,
I have a column where the data is a href with a currency value. Ex:
[code]
$234.23
[/code]
Is is possible to both filter the HTML tags and use the currency sorting plug-in at the same time? Multiple sTypes?
Or do I need to update the currency sorting plug-in to strip the HTML tags?
Thank you for your time!
Cheers,
Randy
I have a column where the data is a href with a currency value. Ex:
[code]
$234.23
[/code]
Is is possible to both filter the HTML tags and use the currency sorting plug-in at the same time? Multiple sTypes?
Or do I need to update the currency sorting plug-in to strip the HTML tags?
Thank you for your time!
Cheers,
Randy
This discussion has been closed.
Replies
[code]
jQuery.fn.dataTableExt.oSort['html-currency-asc'] = function(a,b) {
a = a.replace( /<.*?>/g, "" );
b = b.replace( /<.*?>/g, "" );
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
var x = a == "-" ? 0 : a.replace( /,/g, "" );
var y = b == "-" ? 0 : b.replace( /,/g, "" );
/* Remove the currency sign */
x = x.substring( 1 );
y = y.substring( 1 );
/* Parse and return */
x = parseFloat( x );
y = parseFloat( y );
return x - y;
};
jQuery.fn.dataTableExt.oSort['html-currency-desc'] = function(a,b) {
a = a.replace( /<.*?>/g, "" );
b = b.replace( /<.*?>/g, "" );
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
var x = a == "-" ? 0 : a.replace( /,/g, "" );
var y = b == "-" ? 0 : b.replace( /,/g, "" );
/* Remove the currency sign */
x = x.substring( 1 );
y = y.substring( 1 );
/* Parse and return */
x = parseFloat( x );
y = parseFloat( y );
return y - x;
};
[/code]
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
//Strip HTML TAGS
a = a.replace( /<.*?>/g, "" );
b = b.replace( /<.*?>/g, "" );
a = jQuery.trim(a);
b = jQuery.trim(b);
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
x = a == "-" ? 0 : a.replace( /,/g, "" );
y = b == "-" ? 0 : b.replace( /,/g, "" );
/* Remove the currency sign */
x = x.replace( /\$/g, "" );
y = y.replace( /\$/g, "" );
/* Parse and return */
x = parseFloat( x );
y = parseFloat( y );
return x - y;
};
jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
//Strip HTML TAGS
a = a.replace( /<.*?>/g, "" );
b = b.replace( /<.*?>/g, "" );
a = jQuery.trim(a);
b = jQuery.trim(b);
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
x = a == "-" ? 0 : a.replace( /,/g, "" );
y = b == "-" ? 0 : b.replace( /,/g, "" );
/* Remove the currency sign */
x = x.replace( /\$/g, "" );
y = y.replace( /\$/g, "" );
/* Parse and return */
x = parseFloat( x );
y = parseFloat( y );
return y - x;
};
[/code]