Filtering by date with dataTables how to do - uncomplicating

0

Hello

I am implementing the date filter with jquery dataTable, with the built-in draw () feature. It's a bit complicated so I'd like to see if anyone can understand.

I put the code in the fiddle: link

I'll put here the js excerpt I'm working on:

table = $('.table_master').DataTable({
      paging: false,
      info: false
    });

    // Extend dataTables search
    $.fn.dataTable.ext.search.push(
      function(settings, data, dataIndex) {
        var min = $('#min-date').val();
        var max = $('#max-date').val();
        var createdAt = data[1] || 0; // Our date column in the table

        if (
              (min == "" || max == "") ||
              (moment(createdAt).isSameOrAfter(min) && moment(createdAt).isSameOrBefore(max))
        ){

          return true;

        }

            return false;
            //table.draw();

      }
    );

    $('.date-range-filter').change(function() {     
        table.draw();
    });

The idea is to do a kind of between with the filter, choosing a start date and an end date, getting all results in that range. For example, if I have the dates: "01/06/2018", "02/06/2018", "03/06/2018", "04/06/2018", Then while filtering from 06/01/2018 to 03/06/2018, the table should show the 3 records in the range, 01.02 and 03.

With the current code, I still do not have this result, the filter does not happen ... I would like to see if anyone knows how to implement. In the fiddle I have already put the jquery libraries, dataTables and moment.js that are needed ...

    
asked by anonymous 20.06.2018 / 13:45

0 answers