Datatable - Issues creating multiple date range filters
Datatable - Issues creating multiple date range filters
Hi folks, first time on these forums. Been asking around for a while (http://stackoverflow.com/questions/37313537/datatable-issues-creating-multiple-date-range-filters) but haven't been able to get an answer to this and still stuck on this problem. I was following the guide provided here: https://datatables.net/plug-ins/filtering/row-based/range_dates. This works great when you have a single date range filter. But when I try to introduce multiple date range filters, nothing works as expected or at all.
This is an example of what im trying to accomplish but with multiple date filters. http://www.swartzfager.org/thoughts/demos/dataTablesDateRange/
Here is an example of the issue recreated in a jsfiddle: https://jsfiddle.net/bLd00Lh5/10/
Here is my code:
dtTable = $('#mytable').DataTable();
$('[id^=min_col_date]').bind('change keyup', function() {
start_date = $(this).val();
column_name = $(this).attr("id").slice( -9 );;
dtTable.draw();
});
$('[id^=max_col_date]').bind('change keyup', function() {
end_date = $(this).val();
column_name = $(this).attr("id").slice( -9 );
dtTable.draw();
});
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var filterstart = start_date;
var filterend = end_date;
var iStartDateCol = "."+column_name;
var iEndDateCol = "."+column_name;
var tabledatestart = aData[iStartDateCol];
var tabledateend= aData[iEndDateCol];
if ( filterstart === "" && filterend === "" )
{
return true;
}
else if ((moment(filterstart).isSame(tabledatestart) || moment(filterstart).isBefore(tabledatestart)) && filterend === "")
{
return true;
}
else if ((moment(filterstart).isSame(tabledatestart) || moment(filterstart).isAfter(tabledatestart)) && filterstart === "")
{
return true;
}
else if ((moment(filterstart).isSame(tabledatestart) || moment(filterstart).isBefore(tabledatestart)) && (moment(filterend).isSame(tabledateend) || moment(filterend).isAfter(tabledateend)))
{
return true;
}
return false;
}
);
Been stuck on this for a while now, would any know what im missing? Any help would be appreciated. :)
Answers
You can take a look at my yadcf plugin, it has date range filter and you can place it for multiple columns, see showcase/read docs
Thanks Daniel for your quick answer, I was hoping there would be a solution using just datatable's code. Since i have colreordering activated just seems like its gonna create a lot of problems.
yadcf support col reorder out of the box