Multi Range filter Custom Search
Multi Range filter Custom Search
Hi, im a little new to Datatables but managed to do the following
a short explanation of what is this doing;
It's a 3 range filters does not matter which one starts first but the results will be filtered out by the other 2 range filters and you can see i used the following range filters which they are dataTables custom range filter and Date range filter with moments sorting enabled and there is 2 dataTables in the webpage
Now for my question: is there a way to make these 3 filters not to filter each others results but to filter the original data just like in this
http://live.datatables.net/mucevape/1/edit which is a Mult search box by including other rows that is not included within one or the other filters for and im using a text input fields with an event listener when the user inputs the data it will activates the filters based on which input is being used
//custom filter for TAT Due
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
var min = parseFloat($('#HtMtat').val(), 10);
var max = parseFloat($('#HtMxtat').val(), 10);
var tatD = parseFloat(data[5]) || 0; // use data for the TAT Due column
if ((isNaN(min) && isNaN(max)) ||
(isNaN(min) && tatD <= max) ||
(min <= tatD && isNaN(max)) ||
(min <= tatD && tatD <= max)) {
return true;
}
return false;
}
);
//custom filter for TAC Due
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
var min1 = parseFloat($('#HtMtac').val(), 10);
var max1 = parseFloat($('#HtMxtac').val(), 10);
var tacD = parseFloat(data[6]) || 0; // use data for the TAT Due column
if ((isNaN(min1) && isNaN(max1)) ||
(isNaN(min1) && tacD <= max1) ||
(min1 <= tacD && isNaN(max1)) ||
(min1 <= tacD && tacD <= max1)) {
return true;
}
return false;
}
);
//custom filter for Due Date
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex) {
var filterstart = $('#HtSdate').val();
var filterend = $('#HtEdate').val();
var iStartDateCol = 7; //using column 7 in this instance
var tabledatestart = aData[iStartDateCol];
var tabledateend = aData[iStartDateCol];
if (filterstart === "" && filterend === "") {
return true;
} else if ((moment(filterstart).isSame(tabledatestart) ||
moment(filterstart).isBefore(tabledatestart)) &&
filterend === "") {
return true;
} else if ((moment(filterstart).isSame(tabledatestart) ||
moment(filterstart).isAfter(tabledatestart)) &&
filterstart === "") {
return true;
} else if ((moment(filterstart).isSame(tabledatestart) ||
moment(filterstart).isBefore(tabledatestart)) &&
(moment(filterend).isSame(tabledateend) || moment(filterend).isAfter(tabledateend))) {
return true;
}
return false;
}
This question has an accepted answers - jump to answer
Answers
Hi @mabdulrazzaq ,
No, that's not possible, I'm afraid. As soon as any of the search functions returns a false, then that rows is removed from the search set. That set is then passed onto the next search function - they don't get the original data.
You'll need to do something like that original example you posted, where a single function considers all the properties and makes the decision whether to show or not.
Cheers,
Colin
@colin thanks for replying, I'll give it a try and if it works I'll post the answer here with the code