Disallow searching for specific criteria

Disallow searching for specific criteria

rik1301rik1301 Posts: 2Questions: 1Answers: 0

Hello. I have a table with individual search boxes for 2 of my columns (essentially work the same as the integrated column header search boxes). They are set to exact matches only, and the table data is hidden by default.

I have several thousand rows of "?" and "-" in the column where the full info for that particular record is not yet known. Is there a way to prevent people doing a search for "?" or "-" and displaying all these records please?

Answers

  • kthorngrenkthorngren Posts: 21,339Questions: 26Answers: 4,954

    There is nothing built into Datatables for this. It will a bit of Javascript coding to handle these characters the way you want. Here are a couple options:

    1. You could remove those characters from the search term before calling column().search().
    2. If those characters exist in the search term then don't perform the search and clear the search input. Optionally show an alert stating these characters aren't allowed.

    Kevin

  • rik1301rik1301 Posts: 2Questions: 1Answers: 0

    OK can you show me an example of how to implement this please. Just for clarity, the search is only executed upon pressing enter or clicking the 'search' button alongside, it is not the standard filter-as-you-type.

  • kthorngrenkthorngren Posts: 21,339Questions: 26Answers: 4,954

    Using this example as a base for option 2.
    https://live.datatables.net/xejotevo/1/edit

    It uses column().index() (that.index()) to specify which column to not allow ?. If its 0 then it also makes sure ? is not in the search string. If there is a ? it clears the input and displays an alert. Otherwise it processes the search normally.

    Kevin

Sign In or Register to comment.