Specify a Per Column HTML Data Attribute Search RegEx

Specify a Per Column HTML Data Attribute Search RegEx

jeremysawesomejeremysawesome Posts: 5Questions: 3Answers: 0
edited October 2021 in DataTables 1.10

Description of problem:
Good afternoon. I'm writing regarding a filtering/searching question.

I need to find exact matches of full values (i.e. ^searchTerm$) on some columns and allow the default search on other columns. I'm using html data attributes on th elements to define columns.

Is there a way to override the default search on specific columns via html data attributes? For example, if I wanted to only find full phone numbers, but I want to find partial first names and last names.

<!-- table head -->
    <th>First Name</th>
    <th>Last Name</th>
    <th data-searchRegex="^value$">Phone Number</th>
    <!-- rest of table body -->
</table>

Thank you for your help!
Jeremy

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    Hi Jeremy,

    Nice idea with the attribute, but no, I'm afraid that is not something that DataTables will pick up.

    Are you using a global filter here, or is it individual column filters? For a global filter, you'd need to create a custom plug-in for it. For individual column inputs, each would need to determine how to call the column().search() method (for exact or partial match).

    Allan

  • jeremysawesomejeremysawesome Posts: 5Questions: 3Answers: 0

    Good morning Allan,
    Thank you for your kind response. I am using the global filter and will look into the custom plug-in route.

    Have a stupendous day.
    Jeremy

Sign In or Register to comment.