fnFilter

fnFilter

guillimonguillimon Posts: 2Questions: 0Answers: 0
edited August 2009 in General
Hi all.

How can i use fnFilter for filter with criteria "greater than". I think but, by defaullt, fnFilter filter the data with contains the data input. I don't hoew filter, for instead, if I introduce the numer 5, all rows whith the column greater than 5.

I search in this forum, but i find anything.

Thanks for all

Replies

  • allanallan Posts: 61,654Questions: 1Answers: 10,094 Site admin
    Hi guillimon,

    You can't use fnFilter on it's own for what you are looking for - as you say, it's looking specifically for matching text. What you will need to do is create a filter plug-in. The documentation for this can be found here:
    http://datatables.net/development/filtering

    And there is an example similar to what you are looking for (it has a min values as well) here:
    http://datatables.net/examples/api/range_filtering.html

    Regards,
    Allan
  • guillimonguillimon Posts: 2Questions: 0Answers: 0
    Thank you. I solved the problem, so I can filter in a date range.

    I have two inputs (fini and ffin) for initial date and end date (in format dd-mm-yyy) and two columns in the table (columns 6 and 7).
    I have to convert all dates in format yyyymmdd and filter it,

    I put the code for $.fn.dataTableExt.afnFiltering.push. Maybe is usefull for somebody.
    The rest is the same like the example http://datatables.net/examples/api/range_filtering.html (be careful with the inputs id):

    [code]

    $.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {

    var iFini = document.getElementById('fini').value;
    iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2)

    var iFfin = document.getElementById('ffin').value;
    iFfin=iFfin.substring(6,10) + iFfin.substring(3,5)+ iFfin.substring(0,2)


    var datofini=aData[6].substring(6,10) + aData[6].substring(3,5)+ aData[6].substring(0,2);
    var datoffin=aData[7].substring(6,10) + aData[7].substring(3,5)+ aData[7].substring(0,2);


    if ( iFini == "" && iFfin == "" )
    {
    return true;
    }
    else if ( iFini <= datofini && iFfin == "")
    {
    return true;
    }
    else if ( iFfin >= datoffin && iFini == "")
    {
    return true;
    }
    else if (iFini <= datofini && iFfin >= datoffin)
    {
    return true;
    }
    return false;

    }
    );


    [/code]
  • allanallan Posts: 61,654Questions: 1Answers: 10,094 Site admin
    Hi guillimon,

    Nice one! Thanks very much for sharing your code with us. I've put up a new plug-ins page with your filter on it as a demonstration of how custom filtering can be done with DataTables: http://datatables.net/plug-ins/filtering

    Regards,
    Allan
This discussion has been closed.