Obtain the Matched Columns from the results of a Search
Obtain the Matched Columns from the results of a Search
jeremysawesome
Posts: 5Questions: 3Answers: 0
Consider the manual for the search method:
https://datatables.net/reference/api/search()
It says:
If data is found matching in any column, then the whole row is matched and shown in the result set.
My question is how do I see the columns that matched? i.e. if my table consists of 12 columns and only 2 matched, how can I tell what 2 were matched?
Thank you for your time!
Answers
There is nothing built into Datatables to provide this information. One option is to loop through all the matched rows using
rows().every()
with theselector-modifier
of{search: "applied"}
. In the loop you have access to the row data where you can compare to the search term. The search term can be obtained usingsearch()
.Keep in mind the search term might be a partial match. Also if using Smart search it might not be easy to find the matching column.
If this doesn't help then please provide details of what you are trying to do so we can offer more specific suggestions.
Kevin
If you just want to highlight the matching text take a look at this blog. Possibly the plugin code might help you to find the columns that are matched.
Kevin