I have this datatable:
$(document).ready(function() {
$("#Date_search").val("");
});
var table = $('#tabla').DataTable( {
deferRender: true,
"autoWidth": false,
"search": {
"regex": true,
"caseInsensitive": false,
},});
$('#Date_search').on( 'keyup change', function () {
table.draw();
});
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var min = $("#Date_search").val().split(" to ")[0];
var max = $("#Date_search").val().split(" to ")[1];
var date = data[2] || ""; // use data for the date column
if ( ( isNaN( min ) && isNaN( max ) ) ||
( isNaN( min ) && date <= max ) ||
( min <= date && isNaN( max ) ) ||
( min <= date && date <= max ) )
{
return true;
}
return false;
}
);
$("#Date_search").daterangepicker({
"locale": {
"format": "YYYY-MM-DD",
"separator": " to ",
"applyLabel": "Apply",
"cancelLabel": "Cancel",
"fromLabel": "From",
"toLabel": "To",
"customRangeLabel": "Custom",
"weekLabel": "W",
"daysOfWeek": [
"Su",
"Mo",
"Tu",
"We",
"Th",
"Fr",
"Sa"
],
"monthNames": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
],
"firstDay": 1
},
"opens": "center",
});
<html>
<head>
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
</head>
<body>
Date: <input id="Date_search" type="text" placeholder="Search by Date" /><br>
<table id='tabla'>
<thead>
<td>Date</td>
</thead>
<tbody>
<tr>
<td>2018-05-05</td>
</tr>
<tr>
<td>2018-05-06</td>
</tr>
<tr>
<td>2018-05-07</td>
</tr>
<tr>
<td>2018-05-08</td>
</tr>
<tr>
<td>2018-05-09</td>
</tr>
<tr>
<td>2018-05-10</td>
</tr>
</tbody>
</table>
</body>
</html>
And I can not get it to filter me correctly by the dates.
I followed the DataTable documentation to filter a range of dates and I can not find what is failing me.
I've searched Stackoverflow and the Internet and I can not find any solution to my problem.
Any ideas to make it work?
Thanks
(In case you have to mess around: link )