I have a requirement to search on a specific column for a value within a range. The data within the column is typically of the format 617006, 630002, 753000-753025, 751001, 752001-752003, 755000, 755010 - 755020
In the example above, the user has to be able to search, using the datatables search box, for 753005. I have tried defining my own extension to the search
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex, row, counter) {
console.log(“In extended search function”);
var codes = data[5];
var sSearch = settings.oPreviousSearch.sSearch;
if (codes.includes(sSearch)) {
return true;
}
// check ranges and return true else return false
return isInRange(sSearch, codes);
}
);
If I try to search for 753005 the function is never called, it seems to be called on initialisation or when the global search finds a value. I would like the extension search to be called after the global search to check to see if the value is within one of the ranges.
I tried using (note: code removed)
$.fn.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
console.log("In afnFiltering pushed function");
return true;
}
);
However this has the same behaviour as the search push function.
I have also tried creating a custom type, fmscode, for the column but this is only called on initialisation, never on search and only contains the column data with no extra parameter to get the string to be searched for.
$.fn.DataTable.ext.type.search.fmscode = function (data) {
console.log("In $.fn.DataTable.ext.type.search.fmscode");
return isInRange(data, codes);
};
$('#aTable).DataTable({
"paging": false,
"columnDefs": [
{ "type": "fmscode", "targets": 5, "searchable": true, "orderable": false }
]
});
I had thought about a hidden column that contained only the values within each range but this could become messy as the ranges can be large.
Does anyone know of a way to achieve this type of search?
Thanks