Estend search range filtering server side
Estend search range filtering server side
Miguel_Frazao
Posts: 2Questions: 1Answers: 0
I have done a min (from) and max (to) date so i can get all the rows between those two, based on https://datatables.net/examples/plug-ins/range_filtering.html (witch works great without server side), but doesn't work with server side, I've done:
function to_unix_timestamp(myDate) {
if(myDate != undefined){
myDate=myDate.split("-"); // datepicker format: dd-mm-yyyy
var newDate=myDate[1]+"/"+myDate[0]+"/"+myDate[2];
return new Date(newDate).getTime();
}
}
function date_is_valid(time_now) {
var date = new Date(time_now);
if(date.getTime() > 0) { // if valid timestamp
return true;
}
return false;
}
var columnIndex = $('.interval_inputs').data('columnfilter');
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
alert(); // this doesn't happen when server serverSide = true
var inputMinDate = $('.minDate').val();
var inputMaxDate = $('.maxDate').val();
var unixTimeMin = to_unix_timestamp(inputMinDate);
var unixTimeMax = to_unix_timestamp(inputMaxDate);
var unixTimeRow = to_unix_timestamp(data[columnIndex]);
if(unixTimeMin <= unixTimeMax && date_is_valid(unixTimeRow)) {
if(unixTimeRow >= unixTimeMin && unixTimeRow <= unixTimeMax) {
return true;
}
return false;
}
return true;
}
);
var count = 1;
var columnsNames = [];
$('thead th').each(function() {
columnsNames.push({'data': $(this).data('name')});
});
var table = $('.myDataTable').DataTable({
"processing": true,
"serverSide": true,
"ajax": '/pt/admin/datatables/counties',
"columns": columnsNames,
"createdRow": function ( row, data, index ) {
$('td', row).last().addClass('actions');
},
responsive: true,
});
$('.minDate, .maxDate').on('change', function() {
var minDate = $('.minDate').val();
var maxDate = $('.maxDate').val();
if(minDate != '' && maxDate != '') {
table.draw();
}
else if(minDate == '' && maxDate == '') {
table.draw();
}
});
I would like to make this work on server side too, but doesn’t even do the alert inside the search extend function
This discussion has been closed.
Answers
Thank for this (datatables), it's an awsome tool to use
I'm interested in implementing this code that you've built, but im getting an error that I cant seem to fix.
DataTables warning: table id=myDataTable - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
Any help?