Checkboxes - filter by 'contains string' rather than 'exact string'

Checkboxes - filter by 'contains string' rather than 'exact string'

dtscdtsc Posts: 3Questions: 2Answers: 0
edited December 5 in Free community support

I'm using this code which adds checkboxes that act as filters, placed above a table:

https://live.datatables.net/vipifute/720/edit

These checkbox match exact values. For example, clicking the Javascript Developer checkbox filters exactly on the string "Javascript Developer".

However, let's say there are are also rows that have Python Developer as a Position.

In this case I might want a Developer checkbox, which would check rows that have a Position that CONTAINS the string "Developer". That is, it would match against rows with a Position of Javascript Developer or Python Developer (or any other XYZ Developer).

How can I achieve a checkbox filtering by contains rather than exact match?

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited December 5

    The search is using the regex pattern of '^' + this.value + '$'. The ^ is the start of string token and the $ is the end of string token`. This makes it an exact match. One option is to remove these two tokens. See if this change does what you want:
    https://live.datatables.net/vipifute/873/edit

    Kevin

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Another option is to use smart search. See the search() docs for details. You will want to remove the boolean values from the column().search() to change from regex searching to smart searching. Choose the mode that best fits your needs.

    Kevin

Sign In or Register to comment.