I have the dateMin field default to Jan 1, 1900 which works for my purposes (you may want to go further out if you have dates older).
I have the dateMax field default to today's date using PHP, though I'm sure you could set it via JS as well.
This was the only way I could get all the rows to show up on page load.
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
// Get date range
dateMin = $("#fromSelector").attr("value");
dateMax = $("#toSelector").attr("value");
if (dateMin == "") {
dateMin = "01-01-1900";
}
if (dateMax == "") {
dateMax = "'.date('m-d-Y').'";
}
dateMin = new Date(dateMin);
dateMax = new Date(dateMax);
// 0 here is the column where my dates are.
var date = data[0];
date = new Date(date);
// run through cases
if ( dateMin == "" && date <= dateMax){
return true;
}
else if ( dateMin =="" && date <= dateMax ){
return true;
}
else if ( dateMin <= date && "" == dateMax ){
return true;
}
else if ( dateMin <= date && date <= dateMax ){
return true;
}
// all failed
return false;
}
);
Replies
FYI for those using version 1.10!!
I have the dateMin field default to Jan 1, 1900 which works for my purposes (you may want to go further out if you have dates older).
I have the dateMax field default to today's date using PHP, though I'm sure you could set it via JS as well.
This was the only way I could get all the rows to show up on page load.