Sort issues when using $.fn.dataTable.ext.search
Sort issues when using $.fn.dataTable.ext.search
I have a function that several datatables call. Here is a simplified version of it:
addFilter(tableElement: ElementRef, headerName) {
$.fn.dataTable.ext.search.push(
function (settings, data) {
// check table so we only filter the table that was passed in
if (settings.nTable.id !== tableElement.nativeElement.id) {
return true;
}
const columns = settings.aoColumns;
const columnObject = columns.find(function (column) { return column.sTitle === headerName; });
if (columnObject) {
const columnIndex = columnObject.mData;
if (data[columnIndex] === 'true') {
return true;
} else {
return false;
}
}
}
);
}
So this does what I want, but the issue I am running into now is when I click the sort/order icon on a column, the function that is passed to $.fn.dataTable.ext.search.push is getting called. It is not calling the addFilter function though. Just somehow it is executing the function that is passed into the push. My guess is that when you click the sort icon, it is calling a draw on the table, but I do not understand how my push function would be getting called.
Answers
Hi @DTaylor ,
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