I have two inputs (minimum date and maximum date) with which I want to filter the results of my tables, the problem is that DataTables has a serious problem with the ordering of dates. I have read online that for those who want to have the format dd / mm / YYYY there is a bit of a roll and recommend doing a "trick" which is faster than another option but only works in the search field that has DataTables by default, but with two inputs it does not work.
This "trick" is to put a display none with the date in YYYYMMDD format so the user does not see the content of the DataTables if you can perform the sorting.
<td><span style='display: none;'>20150221</span>21/02/2015</td>
So far with the default search filter of DataTables, the thing is that I would like two inputs and put a range of dates. And with the following code it does not work for me, it starts filtering well but when I finish writing the maximum date it does not filter correctly.
The thing is that I do not know if the first "trick" affects the second case or vice versa, someone who has had the same problem or similar would know how to light up a bit? Here I leave my code.
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iFini = document.getElementById('min').value;
var iFfin = document.getElementById('max').value;
var iStartDateCol = 4;
var iEndDateCol = 4;
iFini = iFini.substring(6,10) + iFini.substring(3,5) + iFini.substring(0,2);
iFfin = iFfin.substring(6,10) + iFfin.substring(3,5) + iFfin.substring(0,2);
var datofini=aData[iStartDateCol].substring(6,10) + aData[iStartDateCol].substring(3,5)+ aData[iStartDateCol].substring(0,2);
var datoffin=aData[iEndDateCol].substring(6,10) + aData[iEndDateCol].substring(3,5)+ aData[iEndDateCol].substring(0,2);
if (iFini === "" && iFfin === "") {
return true;
} else if (iFini <= datofini && iFfin === "") {
return true;
} else if (iFfin >= datoffin && iFini === "") {
return true;
} else if (iFini <= datofini && iFfin >= datoffin) {
return true;
}
return false;
}
);
var table_filter = $('#DataTables_Table_4').dataTable();
$('#min').keyup( function() { table_filter.fnDraw(); } );
$('#max').keyup( function() { table_filter.fnDraw(); } );