Datatable not filtering with datepicker

Datatable not filtering with datepicker

em1000em1000 Posts: 1Questions: 1Answers: 0

0
down vote
favorite
I have a datatable and it is filled with some data but when I want to sort it using a datepicker the whole table disappears and doesnt display anything,but in the console I can see that the data is displaying there like it should only in my page it is not.

'''
$('#reportrange').on('apply.daterangepicker', function (ev, picker) {

    var test = picker.startDate.format('M-D-YYYY');
    var test2 = picker.endDate.format('M-D-YYYY');

    $.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex) {

            var min = test;
            var max = test2;
            var date = parseFloat(data[1]) || 0;

            console.log(min);
            console.log(data);
            console.log(max);

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

            ) {

                return true;
            } else { return false; }



        }
    );
    var table = $('#myTable1').DataTable();

    table.draw();

});

'''

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Without seeing a test case its hard to say but I suspect the problem is due to passing a float to the moment function moment(date).isSameOrAfter(min). According to the docs it takes a string with certain formats:
    https://momentjs.com/docs/#/parsing/string/

    You need to troubleshoot what is going on with your if statement. The comparison is always returning false.

    Kevin

This discussion has been closed.