filtering rows by date within date range
filtering rows by date within date range
petervanrees
Posts: 2Questions: 0Answers: 0
Hi,
I'm using this code to add filtering by date within a date range:
[code]
$.fn.dataTableExt.afnFiltering.push(
function ( oSettings, aData, iDataIndex ) {
var dateMin = aData[3].substring(0,4) + aData[3].substring(5,7) + aData[3].substring(8,10);
var dateMax = aData[4].substring(0,4) + aData[4].substring(5,7) + aData[4].substring(8,10);
var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
if(day<10){day='0'+day} if(month<10){month='0'+month}
var currdate = year + month + day;
//alert(currdate + " " + dateMin + " " + dateMax);
if ( dateMin == "" && currdate <= dateMax) { return true; }
else if ( dateMin == "" && dateMax == "") { return true; }
else if ( dateMin <= currdate && dateMax == "") { return true; }
else if ( dateMin <= currdate && currdate <= dateMax ) { return true; }
// all failed
return false;
});
[/code]
and this is the handler which should trigger the filter (within the document.ready function) :
[code]
$('#datefilter').click( function () {
oTable.fnDraw();
});
[/code]
the problem is that this does not filter, but it merely hides the data that does not fit the filter, yet the empty rows are still shown. Any ideas why the entire rows that don't match the filter are not hidden? I'm afraid I can't give you a link, there's privacy sensitive data.
I'm using this code to add filtering by date within a date range:
[code]
$.fn.dataTableExt.afnFiltering.push(
function ( oSettings, aData, iDataIndex ) {
var dateMin = aData[3].substring(0,4) + aData[3].substring(5,7) + aData[3].substring(8,10);
var dateMax = aData[4].substring(0,4) + aData[4].substring(5,7) + aData[4].substring(8,10);
var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
if(day<10){day='0'+day} if(month<10){month='0'+month}
var currdate = year + month + day;
//alert(currdate + " " + dateMin + " " + dateMax);
if ( dateMin == "" && currdate <= dateMax) { return true; }
else if ( dateMin == "" && dateMax == "") { return true; }
else if ( dateMin <= currdate && dateMax == "") { return true; }
else if ( dateMin <= currdate && currdate <= dateMax ) { return true; }
// all failed
return false;
});
[/code]
and this is the handler which should trigger the filter (within the document.ready function) :
[code]
$('#datefilter').click( function () {
oTable.fnDraw();
});
[/code]
the problem is that this does not filter, but it merely hides the data that does not fit the filter, yet the empty rows are still shown. Any ideas why the entire rows that don't match the filter are not hidden? I'm afraid I can't give you a link, there's privacy sensitive data.
This discussion has been closed.