Sorting & Filtering

Sorting & Filtering

rmodosrmodos Posts: 2Questions: 0Answers: 0
edited May 2011 in General
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

Replies

  • the3rdbitthe3rdbit Posts: 8Questions: 0Answers: 0
    edited May 2011
    Just combinate these two Plugins.

    [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]
  • rmodosrmodos Posts: 2Questions: 0Answers: 0
    [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]
This discussion has been closed.