replace default filtering (but keep filtering box)
replace default filtering (but keep filtering box)
Hi,
I seem unable to replace the default filtering.
I want to keep the default GUI search box, but I want my function to run instead of it combining the default and my custom.
Problem is , my custom search is an OR, but the default search creates it as an AND, so I'm not getting rows returned.
How do I override the default search function without having to use my own DOM control or how do I make the custom search and the default search work together as an OR not an AND?
here is my custom filter...
// data tables custom search to include genres, styles, labels not displayed in GUI
// case insensitive
$.fn.dataTableExt.afnFiltering.push(
function (settings, data, dataIndex) {
var search = $('.dataTables_filter input').val();
var found = false;
if (search == '') {
found = true;
}
else {
// check displayed values
// barcode
if (data[0].toLowerCase().includes(settings.oPreviousSearch.sSearch.toLowerCase())) { found = true; }
//cat no
if (data[1].toLowerCase().includes(settings.oPreviousSearch.sSearch.toLowerCase())) { found = true; }
// title
if (data[2].toLowerCase().includes(settings.oPreviousSearch.sSearch.toLowerCase())) { found = true; }
// year
if (data[3].toLowerCase().includes(settings.oPreviousSearch.sSearch.toLowerCase())) { found = true; }
// don't waste time if already found
if (!found)
{
// loop Genres
$.each(settings.aoData[dataIndex]._aData.Genres, function (i, obj) {
if (obj.genre.toLowerCase().includes(settings.oPreviousSearch.sSearch.toLowerCase())) {
found = true;
}
});
// loop Styles
$.each(settings.aoData[dataIndex]._aData.Styles, function (i, obj) {
if (obj.style.toLowerCase().includes(settings.oPreviousSearch.sSearch.toLowerCase())) {
found = true;
}
});
// loop Labels
$.each(settings.aoData[dataIndex]._aData.Labels, function (i, obj) {
if (obj.label.toLowerCase().includes(settings.oPreviousSearch.sSearch.toLowerCase())) {
found = true;
}
});
}
}
return found;
}
);
Answers
I refused to be beat, and I finally found the answer I was looking for.
My solution required no changes to anything, no custom filter, no fancy replacement of the default search.
For those that have the same type of complex data structure, that you want to search but not show, use this syntax....
You will see the Styles & Labels are defined as being an array [] , you put a comma in the square brackets to tell it to comma separate and then you add the dot notation for the object attribute you want concatenating.
The hidden columns will then have data like this...
Styles: House,Progressive House,Tech House
Labels: Decadance Recordings,Demon Music Group Ltd.,Sony DADC UK Ltd.
Which is therefor searchable!
Simple when you know how
Brilliant . Thanks for posting back with the solution.
Allan
No problem, it's the least I could do considering the effort you and the community have put into this awesome plugin!