Ignore HTML tags in the search
Ignore HTML tags in the search
Link to test case: https://live.datatables.net/lufumimi/1/
Debugger code (debug.datatables.net):
Error messages shown: NA
Description of problem: Hello,
I would like to know how to configure the columns or the search function so that searches are performed only on the text actually displayed within the data table columns.
Please refer to the test case mentioned at the beginning of the message.
For instance, if you look at the "id" column and perform a search; whether via the column header or a global search; you will notice that the search takes into account ALL the characters present in the column's HTML, rather than just the content actually displayed.
In other words, every character within <span class="badge badge-danger p-2 link-id">0000X</span> can trigger a match, instead of just the value 00001.
I am certain that this is possible, because exporting or copying the rows (using the buttons) only preserves the information actually displayed on the screen.
Thank you in advance for your help, and I wish you a pleasant day.
Answers
Is wrong. It should be
{type : "html"},to have thefilterdata type strip out the HTML: https://live.datatables.net/lufumimi/2/edit .In general, I would strongly recommend not setting the
columns.typeoption. To the point that I regret putting it in as an option! Let DataTables figure out the data type for you, and if it doesn't match, then forcing it to be something else would just result in something unexpected happening (like here).Allan
Hello @allan,
Thank you very much, this is exactly what I need.
And apologies for having overlooked this option. I had seen it before, but I didn’t remember it.
One more question.
You stated the following:
But how should I initialize my
columnsarray?Should I set it to
"null"everywhere?Have a great day.
You can either use
nullor an empty object:Another option is to use
columnDefsto target the two columns which do need a configuration object.Allan