How to refresh when I select a date

How to refresh when I select a date

massivemassive Posts: 1Questions: 0Answers: 0

my datatables codes are

    var table;
    $(document).ready(function() {
   table= $('#example').DataTable({
    "applyFilter":true,

        "processing" : true,
        "select":false,
        "ajax" : {
            "url" : "http://localhost:3000/zamansecimi2",
            dataSrc : 'data'
        },
        "columns" : [ {
            "data" : "id"
        }, {
            "data" : "mac"
        },{
            "data" : "x"
        },{
            "data" : "y"
        },{
            "data" : "oncekizaman",
            type:  'datetime',
                def:   function () { return new Date(); }

        },{
            "data" : "zaman",type:  'datetime',
                def:   function () { return new Date(); }
        }
      ]
    })



});





    minDateFilter = new moment($('#bas').val())
maxDateFilter = new moment($('#bit').val())
 var startDate = minDateFilter,
        endDate = maxDateFilter;




        $.fn.dataTableExt.afnFiltering.push(
        function( settings, data, dataIndex ) {
          const format2 = "YYYY-MM-DD"

            var min = moment(minDateFilter).format(format2);
            var max  =moment(maxDateFilter).format(format2);

            var createdAt = data[4] || 0; // Our date column in the table
            var dateTime2 = moment(createdAt).format(format2);
            //createdAt=createdAt.split(" ");
            var startDate   = min;
            var endDate     = max;
            var diffDate = dateTime2;

            console.log(dateTime2);
            if (
              (min == "" || max == "") ||
              (
                //diffDate.isBetween(startDate, endDate)
             moment(diffDate).isSameOrAfter(min) && moment(diffDate).isSameOrBefore(max))


            ) {  return true;  }
            return false;

        }
    );







// Date range filter
function getir(){
  location.reload();
}

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

});

my html codes are

       <div class="input-daterange">
                  <label for="start">Başlangıç</label>
                  <input type="date" name="bas"   id="bas"    placeholder="" >
                </div>
                <div class="form-group">
                  <label for="end">Bitiş</label>
                  <input type="date"  name="bit" id="bit" placeholder="" >
                </div>

            <input class="button"  type="button" value="Raporu Getir" id="filter" onclick="getir();"/></input>

When I select date from datepicker it is not refreshing the table.why?how can I fix my problem?

thank you for your help

Replies

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    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

This discussion has been closed.