Obtain the Matched Columns from the results of a Search

Obtain the Matched Columns from the results of a Search

jeremysawesomejeremysawesome 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

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited April 2023

    There is nothing built into Datatables to provide this information. One option is to loop through all the matched rows using rows().every() with the selector-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 using search().

    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

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited April 2023

    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

Sign In or Register to comment.