Range Filtering, from AGE to DATE with example.
Range Filtering, from AGE to DATE with example.
Hi All,
I was curious if it was possible to edit between 2 dates based on the example of the range filter between 2 values. The example shows age, which is the 4th column along (starting from 0 in an array). I changed this column to 5, which selects the start date.
Example: http://datatables.net/examples/plug-ins/range_filtering.html
With the example there is a min and max age inputs, and if you filter with the example columns, it works. That is until you hit the (/ forward slash) in the date. For example, 2011/05. As soon as there is a character, either / or - which is often used in mysql result set, the filter doesnt work.
Is there a simple way to allow these charachers to be filtered out so when searching between the 2 inputted values, a forward slash can be used. This would then lead to an easy solution to add a datepicker into the input fields.(?)
Thanks for reading, I hope i made it clear.
/* Custom filtering function which will search data in column four between two values */
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var min = $('#min').val() * 1;
var max = $('#max').val() * 1;
var age = parseFloat( data[3] ) || 0; // use data for the age column
if ( ( min == '' && max == '' ) ||
( min == '' && age <= max ) ||
( min <= age && '' == max ) ||
( min <= age && age <= max ) )
{
return true;
}
return false;
}
);
$(document).ready(function() {
var table = $('#example').DataTable();
// Event listener to the two range filtering inputs to redraw on input
$('#min, #max').keyup( function() {
table.draw();
} );
} );