Losing Data on Date range filter
Losing Data on Date range filter
gorhell
Posts: 1Questions: 1Answers: 0
I have this code that filters datatable data on page but once I remove the dates and filters it. It also remove the data and won't go back to the original state of the table when there is no filter.
$('.min').datepicker({
autoHide: true,
format: "yyyy-mm-dd"
});
$('.max').datepicker({
autoHide: true,
format: "yyyy-mm-dd"
});
//var test = $('.min').val();
//$('.min').datepicker({ onSelect: function () { table.draw(); }, changeMonth: true, changeYear: true });
//$('.max').datepicker({ onSelect: function () { table.draw(); }, changeMonth: true, changeYear: true });
var table = $('#userDataTable').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
columnDefs: [{
targets: [0], visible: false
}]
} );
//table.column(0).visible(false);
//table.row( ':eq(0)' ).delete();
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var min = $('.min').val();
var max = $('.max').val();
//alert(min);
//alert(max);
//var startDate = new Date(data[0]);
if ( settings.nTable.id !== 'userDataTable' ) {
return true;
}
var startDate = data[0];
//alert(startDate);
if (min == null && max == null) return true;
if (min == null && startDate <= max) return true;
if (max == null && startDate >= min) return true;
if (startDate <= max && startDate >= min) return true;
return false;
}
);
$('.deletedateagent').click(function () {
$('.min').val("");
$('.max').val("");
// $('#userDataTable').trigger('sortReset');
table.fnFilterClear();
// return false;
});
// Event listener to the two range filtering inputs to redraw on input
$('.min, .max').change(function () {
table.draw();
});
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin