filter with date not working when the min date not existe in table

filter with date not working when the min date not existe in table

BlidaAlgBlidaAlg Posts: 9Questions: 4Answers: 0

hello,
i'm triying to filter datatable with min and max date for one column , everything work only one thing when the date min is not existe in the table,
this is my code
and thanks for helping

require(['datatables', 'jquery'], function(datatable, $) 
            {
              $.fn.dataTable.ext.search.push(
                  function( settings, data, dataIndex ) {
                      var min = Date.parse($('#date').val());
                      var max = Date.parse($('#date_next').val());
                      var age = Date.parse( data[3] ) || 0; // use data for the age column

                      if ((isNaN(min) && isNaN(max)) || 
                          (isNaN(min) && age <= max)  || 
                          (isNaN(max) && age >= min)  || 
                          (age <= max && min <= age)) 
                      {
                        return true;
                      }
                      return false;
                  }
              );
 $('#date, #date_next').click(function() 
                {
                 $('#myTable').DataTable().draw();
                });
              });

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,953
    Answer ✓

    Is this a duplicate question of your other thread ?

    Kevin

  • BlidaAlgBlidaAlg Posts: 9Questions: 4Answers: 0

    No it's not ... the first question the filter not working at all but this question it work but when i try to use a date > date existe in data base the filter not working that why i ask a new question

  • BlidaAlgBlidaAlg Posts: 9Questions: 4Answers: 0

    It work now
    this is my code , thanks a lot

    $.fn.dataTable.ext.search.push(
                      function( settings, data, dataIndex ) 
                      {
                          var min =  $('#date').val();
                          var max =  $('#date_next').val();
                          var date_db =  data[3]  || 0; // use data for the date column
                   
                           if (min == "" && max == "") { return true; }
                           if (min == "" && date_db <= max) { return true;}
                           if(max == "" && date_db >= min) {return true;}
                           if (date_db <= max && date_db >= min) { return true; }
                           return false;
                      });
    
This discussion has been closed.