日期范围过滤器(数据表)不起作用

时间:2019-06-17 14:45:10

标签: jquery datatables datefilter

我正在使用Datatable进行过滤。数据表工作正常(基本功能),但是当我添加日期过滤器时,它实际上不起作用,表中的所有数据都消失了,谁能帮助我找到问题所在。这是我的代码。

自定义JS文件

$(document).ready(function () {

$.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex) {
            var min = $('#min').datepicker("getDate");
            var max = $('#max').datepicker("getDate");
            // need to change str order before making  date obect since it uses a new Date("mm/dd/yyyy") format for short date.
            var startDate = new Date(data[5]);
            console.log(startDate);
        }
);


$("#min").datepicker({onSelect: function () {
        alert('HERE');
        table.draw();
    },
    changeMonth: true,
    changeYear: true,
    dateFormat: "d/m/y"
});
$("#max").datepicker({onSelect: function () {
        table.draw();
    },
    changeMonth: true,
    changeYear: true,
    dateFormat: "d/m/y"
});
var table = $('#order-table').DataTable();

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

我的查看文件:

<table border="0" cellspacing="5" cellpadding="5">
                            <tbody>
                                <tr>
                                    <td>Minimum Date:</td>
                                    <td><input name="min" id="min" type="text" autocomplete="off"></td>
                                </tr>
                                <tr>
                                    <td>Maximum Date:</td>
                                    <td><input name="max" id="max" type="text" autocomplete="off"></td>
                                </tr>
                            </tbody>
                        </table>
                        <table class="table table-bordered table-hover table-striped" id="order-table">
                            <thead>
                                <tr>
                                    <td>Order Number</td>
                                    <td>Customer Name</td>
                                    <td>Customer Email</td>
                                    <td>Customer Address</td>
                                    <td>Customer Phone</td>
                                    <td>Order Date</td>
                                    <td>Total</td>
                                    <td>Status</td>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($orders as $order)
                                <tr>
                                    <td>
                                        <a href="{{ route('order-details', ['id' => $order->id]) }}">
                                            {{ $order->order_no }}
                                        </a>
                                    </td>
                                    <td>{{ App\User::find($order->user_id)->name }}</td>
                                    <td>{{ App\User::find($order->user_id)->email }}</td>
                                    <td>{{ App\UserMeta::getUserMeta($order->user_id, 'address1') }}</td>
                                    <td>{{ App\UserMeta::getUserMeta($order->user_id, 'phone') }}</td>
                                    <td>{{ $order->created_at->format('m/d/Y') }}</td>
                                    <td>{{ $order->total }}</td>
                                    <td>{{ $order->status }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>

我不知道自己在犯什么错误,我尝试了stackoverflow,jsfiddle和Codepen的许多解决方案,但没有一个对我有用。

0 个答案:

没有答案