weixin_33690963 2019-10-19 19:55 采纳率: 0%
浏览 64

数据表日期选择器格式

I have a problem with multiple filtering on column start date of my table. This column is filled with row data formatted as ('dd-mm-yy'). I apply this format to my datepicker but when it try to filtering data on the table it seems to not working.

This is my Javascript code:

     $(document).ready(function(){
    $.fn.dataTable.ext.search.push(
    function (settings, data, dataIndex) {
        var min = $('#min').datepicker("getDate");
        var max = $('#max').datepicker("getDate");
        var startDate = new Date(data[4]);
        if (min == null && max == null) { return true; }
        if (min == null && startDate <= max) { return true;}
        if(max == null && startDate >= min) {return true;}
        if (startDate <= max && startDate >= min) { return true; }
        return false;
    }
    );


        $("#min").datepicker({ 
        dateFormat: 'dd-mm-yy', onSelect: function () { table.draw(); }, changeMonth: true, changeYear: true  });
        $("#max").datepicker({ 
        dateFormat: 'dd-mm-yy',onSelect: function () { table.draw(); }, changeMonth: true, changeYear: true  });
        var table = $('#example').DataTable();

        // Event listener to the two range filtering inputs to redraw on input
        $('#min, #max').change(function () {

            table.draw();
        });
    });

This is JsFiddle

  • 写回答

1条回答 默认 最新

  • weixin_33728708 2019-10-19 20:13
    关注

    The line var startDate = new Date(data[4]); is reading your date as mm-dd-yyyy and this brings to invalid dates. Change it to the following line and you are good to go:

    var startDate = new Date(data[4].substr(6,4), data[4].substr(3,2)-1, data[4].substr(0,2));
    

    Here is the JSFiddle

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大