Custom Search Option
Custom Search Option
Hi,
I would like to have the option of searching only in one column only by typing <columnName>:<string> in the search box. Is this possible? Some of my columns have icons in it like:
{
"targets": 4,
"render": function (data, type, full, meta) {
// If it is rendering the cell contents
if (type === 'display') {
switch (data) {
case 0:
return '<span style="font-size:75%" class="fa-stack fa-lg"><i class="fa fa-unlock fa-stack-2x" style="color:#71BF3D"></i></span>';
case 1:
return '<span style="font-size:75%" class="fa-stack fa-lg"><i class="fa fa-lock fa-stack-2x" style="color:#E74C3C"></i></span>';
default:
return '<span>-</span>';
}
}
return (isNaN(data)) ? -1 : +data;
}
}
Would this kind of values actually work with the search box?
I'm fairly new in using DataTables, so please be gentle
Thanks in advance!
Answers
AFAIK, there is no such search facility in DataTables. You would need to create - as your title says - a custom search procedure.
Incidentally, from looking at your "targets: 4" example, what might you search for in that column?
I want to make it search by something like col4:green and I should see only the ones with green icon
I asked because that's not a very intuitive search for the average user. (And of course you would need to use "green" instead of its hex value.)
(I use the word "average" from my own experience of users, which might differ greatly from yours!)
Searching by icon column it's a thing for the future, but for start I want to go for the columns that have strings in it or values, like the regular search behaviour but adding the name of the column in which to search. Thanks a lot for your answer!