Search() found in hidden columns
Search() found in hidden columns
hey guys,
im facing the following problem: I have a Datatable with a searchfield.
If the Term is found, the table gets filtered and the found string gets marked (jquery.mark()).
I have 2 hidden columns in my table, which shall be searched aswell. If the term is found in the row->hidden cell I want so show an sign which sais something like 'found in field name' (which is hidden)
how could i achieve to determine in which cell the matched string is if it is hidden?
Many thanks in advance
This question has an accepted answers - jump to answer
Answers
One option might be to use
filter()
to see if the search term is found in the hidden columns. You can get the search term usingsearch()
. You can usecolumn-selector
to select the hidden columns using the selector:hidden
. Finally use thecount()
API to count how many times the search term appears in the hidden columns. Here is a simple example:http://live.datatables.net/bozuqitu/1/edit
It looks for the number of times
17
appears in the hidden columns (3). Note there are a total of 417
values in the table, one is shown.The trick is to change the comparison to work with either regex or smart searching. These search modes are described in the
search()
docs.Hope this gets you started.
Kevin
Thank you for your fast answer and for your help. So far I get the desired data and can compare it with my searchString. Now i want show the sign/hint that the term was found in an hidden field (see screenshot)
My code setup is the following:
columns: [
.
.
.
{ data: null,
searchable: false,
width: '15px',
defaultContent: '',
},
.
.
.
drawCallback: function( settings ) {
}
How can I change the html of the cell dynamically? Is this a good approach? First idea was to set the html in the column definition under default content (with css display:none) and then just show it if the condition in the drawcallback is true.
Hope I made my intention clear ^^
Best regards,
Andi
Yep, either
drawCallback
orrowCallback
sounds like the place for that,Colin
Hey Colin,
Thank you for the answer, rowCallback did the trick!
Best regards