As you can see in the sreenshot below, I have DOB in date format. Now I need to search max/min age based on the DOB. For example, if I input range between 10 and 15, DOB within this age range should be retrieved. (So far, it works if I have to search the age as an integer when it is already in a column.) Any idea how I can achieve this.
What I have tried
$.fn.dataTable.ext.search.push(
function( dateString,settings, data, dataIndex ) {
var min = parseInt( $('#min').val(), 10 );
var max = parseInt( $('#max').val(), 10 );
var age = parseFloat( data[5] ) || 0; // use data for the age column
var today = new Date();
var birthDate = new Date(dateString);
// var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if ( m < 0 || (m === 0 && today.getDate() < birthDate.getDate()) || ( isNaN( min ) && isNaN( max ) ) ||
( isNaN( min ) && age <= max ) ||
( min <= age && isNaN( max ) ) ||
( min <= age && age <= max ) )
{
return true;
}
return false;
}
);
var table = $('#example').DataTable();
// Event listener to the two range filtering inputs to redraw on input
$('#min, #max').keyup( function() {
table.draw();
} );