custom filter working inverse to the example in the docs
custom filter working inverse to the example in the docs
hello and sorry for my bad english.
I have problems with custom filter. the fault lies in that the filters operate in reverse of what is presented in the example docs https://datatables.net/examples/plug-ins/range_filtering.html
the problem i have is the filter working excluding the data, if i look some data from 20/08/2018 to 22/08/2018. the result is excluding the date 20,21 and 22(dont work as i want)
the other filter is a select and when i look for a specific value as 2 it return all ecept 2 and that i dont want. is excluding 2
i want include filter and dont exclude.
part of the problem a see is because i return false when return true in the example of the docs but if i return true then the table dont work, the table filters when it draw the first time.
the code that I have.
$(document).ready(function()
{
//using codeigniter 3 as backend
table_auditoria = $('#table_auditoria').DataTable({
"order": [ 0,'asc'], //[ 9,'asc']], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": base_url+"controller/method",
"type": "POST",
},
"columns": [
{ "data": 0 },
{ "data": 1 },
{ "data": 2 },
{ "data": 3 },
{ "data": 4 },
{ "data": 5 },
{ "data": 6 },
],
//Set column definition initialisation properties.
"columnDefs": [
/*{
"targets": [ 0 ], //first column / numbering column
"orderable": false, //set not orderable
},*/
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
],
});
$.fn.dataTableExt.afnFiltering.push(
function(Settings, Data, DataIndex)
{
var date_crude = $('#rango-fechas1').val();// get the date from the search
var topico = $('#topico').val(); //is a num
/*if (topico != 0)
{
if (topico != Data[6]) { //
return false;
}
}*/
if (date_crude != "")
{
// change the date to dd/mm/yyyy TO yyyy/mm/dd
var data_date = Data[3].split("/");// use data for the date column
var data_date_string = data_date[2]+"/"+data_date[1]+"/"+data_date[0];
var fecha = new Date(data_date_string).getTime();
var date_convert = date_crude.split("-"); // separa la fecha minima y la maxima
var min = convert_date(date_convert[0]); // change the date to dd/mm/yyyy TO yyyy/mm/dd
var max = convert_date(date_convert[1]); // change the date to dd/mm/yyyy TO yyyy/mm/dd
if ( (( isNaN(min) && isNaN(max)) ||
(isNaN(min) && fecha <= max) ||
(min <= fecha && isNaN(max)) ||
(min <= fecha && fecha <= max)) )
{
return false;
}
}
return true;
}
);
});
Replies
Hi @david fernandez ,
We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. 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