3

I am using jQuery DataTables in some of my HTML tables. Well, I have a page where I list severral tables and I have to filter all of them by the same filters. In the case is a date range that I customized.

All of the tables use the same css class to construct the dataTable and the search by date-range i did at

$.fn.dataTableExt.afnFiltering.push(fn).

I also have another search by text, using

$('.dataTable').dataTable().fnFilter(
    searchVal,
    4,
    false,
    true
);

and this one is also working in only one table, not in them all as I was expecting to be.

Thanks,

2
  • 1
    possible duplicate of how to put multiple jquery dataTables in one page? Commented Oct 29, 2012 at 1:05
  • It's not duplicate, OP is asking for custom filters working in each instance of DataTables with a isolated scope Commented Aug 18, 2017 at 17:54

1 Answer 1

1

did you notice this Range filtering (dates)

Show details Filter a column on a specific date range. Note that you will likely need to change the id's on the inputs and the columns in which the start and end date exist.

$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
    var iFini = document.getElementById('fini').value;
    var iFfin = document.getElementById('ffin').value;
    var iStartDateCol = 6;
    var iEndDateCol = 7;

    iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2)
    iFfin=iFfin.substring(6,10) + iFfin.substring(3,5)+ iFfin.substring(0,2)       

    var datofini=aData[iStartDateCol].substring(6,10) + aData[iStartDateCol].substring(3,5)+ aData[iStartDateCol].substring(0,2);
    var datoffin=aData[iEndDateCol].substring(6,10) + aData[iEndDateCol].substring(3,5)+ aData[iEndDateCol].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;
});

also

Range filtering (numbers) Filter a specific numeric column on the value being between two given numbers. Note that you will likely need to change the id's on the inputs and the column in which the numeric value is given.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for this. Well, it's pretty much what I did, and it will still work on only one table, not in a range. Upvote because it works, but still will not solve my problem. As I saw up there in a comment, seems that I can do this in a .each() and will work. I'm gooing to test this right now. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.