table.fnDraw() issue on jquery

table.fnDraw() issue on jquery

GowthamNarenGowthamNaren Posts: 1Questions: 1Answers: 0
edited March 16 in Free community support

Hi there,
I have been working on date filter using data-table jquery. On button click, I used to filter dates on from & to dates. I could not get a date filter at once, I supposed to click two times to filter the data table based on dates.
My code:

$(function(){       
   var min;
   var max;
  
    // Event listener to the two range filtering inputs to redraw on input
 $("#btn-filter").click(function(e){
 e.preventDefault();
 var table = $('#customers').DataTable(); 
      min = new Date($("#min")[0].value).format('MM/dd/yyyy');
      max = new Date($("#max")[0].value).format('MM/dd/yyyy');

     table.fnDraw();
     
     
      $.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {  /*On dubugging I found that on 1st click  it stops here, and 2nd click its excute properly*/
        var iFini = min;
        var iFfin = max;
        var iStartDateCol = 7;
        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;
    }
);
 
});  
  });

Let me know how does it work on a single click on filter data table based on dates.

Answers

  • colincolin Posts: 4,013Questions: 0Answers: 710

    Hi @GowthamNaren ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.