Filtering by date with dataTables how to do - uncomplicated

Asked

Viewed 784 times

0

Hello!

I’m implementing the data filter with jquery datatable, with the draw() feature embedded. It’s a little complicated so I’d like to see if anyone can understand.

I put the code in the fiddle: https://jsfiddle.net/8bnLwu47/12/

I’ll put here the section of js 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 make a kind of between with the filter, choosing an initial date and a final date, obtaining all the results in this interval. For example, if I have the dates: "01/06/2018","02/06/2018","03/06/2018","04/06/2018", so when filtering from 01/06/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 someone knows how to implement. In fiddle already put the jquery libraries, dataTables and Moment.js that are needed...

  • Reinforcing the idea, the need is to perform the filter with jquery, where the . draw() is referenced by the resource, based on the date column in the table.

  • In this case the filter through the inputs, defining initial date and final date, would occur without the need to query the BD...

  • Hello, would anyone know a way to filter into the dataTables with this format? https://jsfiddle.net/8bnLwu47/12/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.