Filter Range, but how do i make it ignore pound symbols etc

Filter Range, but how do i make it ignore pound symbols etc

benjashbenjash Posts: 13Questions: 0Answers: 0
edited August 2009 in General
Hi

Having a few issues with pound symbols.

When I add them to the table the filter cannot find the range properly.

I need to strip the pound symbols somewhere in the filter thing? kind of lost..

http://www.wearehome.com/testrane.php
[code]

/* Custom filtering function which will filter data in column four between two values */
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = document.getElementById('min').value * 1;
var iMax = document.getElementById('max').value * 1;
var iVersion = aData[4] == "-" ? 0 : aData[4] * 1;
if ( iMin == "" && iMax == "" )
{
return true;
}
else if ( iMin == "" && iVersion < iMax )
{
return true;
}
else if ( iMin < iVersion && "" == iMax )
{
return true;
}
else if ( iMin < iVersion && iVersion < iMax )
{
return true;
}
return false;
}
);

$(document).ready(function() {
/* Initialise datatables */
var oTable = $('#mytablex').dataTable({

"aoColumns": [
/* Engine */ null,
/* Engine */ null,
/* Browser */ null,
/* Grade */ null,
/* Monthly price */ { "sType": "currency" },
/* Full price */ { "sType": "currency" }
]
});

/* Add event listeners to the two range filtering inputs */
$('#min').change( function() { oTable.fnDraw(); } );
$('#max').change( function() { oTable.fnDraw(); } );
} );
[/code]

Replies

  • benjashbenjash Posts: 13Questions: 0Answers: 0
    [code]

    .m:before
    {
    content: "£";
    }
    [/code]

    Found a very dirty hack. using css selectors. Could really do with working this out so it works in all browsers
  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin
    Assuming that the content that you want is in 'aData[4]', can you not just to aData[4].replace('£', '');?

    Allan
  • benjashbenjash Posts: 13Questions: 0Answers: 0
    edited August 2009
    you my freind are clearly a genius.
    [code]
    $.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {

    var iMin = document.getElementById('min').value * 1;
    var iMax = document.getElementById('max').value * 1;

    var iVersion = aData[4].replace('£', '') == "-" ? 0 : aData[4].replace('£', '') * 1;

    if ( iMin == "" && iMax == "" )
    {
    return true;
    }
    else if ( iMin == "" && iVersion < iMax )
    {
    return true;
    }
    else if ( iMin < iVersion && "" == iMax )
    {
    return true;
    }
    else if ( iMin < iVersion && iVersion < iMax )
    {
    return true;
    }
    return false;
    }
    );

    [/code]
    http://www.wearehome.com/testrane.php


    UPDATE!

    Adding a regular expression that removes both £ and "a month" strings


    [code]
    var patt1 = /£|a month*/ig;

    var iVersion = aData[4].replace(patt1, '') == "-" ? 0 : aData[4].replace(patt1, '') * 1;
    [/code]
  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin
    Excellent stuff. Looks like a nice demo - like the use of the sliders! I might have asked already, but if not, when you are finished, would you be willing to post your use of DataTables in the 'How do you use' thread ( http://datatables.net/forums/comments.php?DiscussionID=230 )?

    Thanks!
    Allan
  • benjashbenjash Posts: 13Questions: 0Answers: 0
    Just building the bare bones! nearly there.

    this is my prototype. complete. It pulls data server side from xml and

    http://www.wearehome.com/testrane.php

    Next phase is pull the database from a msql database apposed from doing loads of adding up php side. Cut the load on the server !

    Phase after that will be pull direct from the mysql database via ajax!

    Thanks for your help Allan, had to learn all this from stratch in the last couple of weeks our web developer quit!

    Im actually a graphic designer... learning jquery, php xml and so on. Been a bit of a nightmaire luckily i used actionscripting way back so its good foundation for Jquery.
This discussion has been closed.