Column search exact match on multiple strings

Column search exact match on multiple strings

dylanmacdylanmac Posts: 49Questions: 7Answers: 1

I want to search a single column for multiple exact strings. They need to be exact because some values are substrings of other values, e.g. A4, A4 Hedged, B4, B4 Hedged, etc. I am using a checkbox control that adds values to a concatenated string (using pipes ( "|" ) as the delimiter) when clicking each box. The resulting search could be: search column A for "A4" or "B4 Hedged" but NOT "A4 Hedged". How do I construct my search parameters to get the result I want? The closest I came was using regex:

.search( searchString === null ? '' : "(^|\s)"+ searchString.replace('|','(\s|$)(^|\s)') + "(\s|$)", true, false );

The above is beginning the search with (^|\s), then inserting (\s|$)(^|\s) between each substring then ending with (\s|$)

Anyway, this doesn't work. Any suggestions are welcome.

Thanks.

Answers

  • dylanmacdylanmac Posts: 49Questions: 7Answers: 1

    Well I figured out the answer to my question. Hopefully this helps someone else in the future:

    table.column( tableColIndex)
    .search( searchString === null ? '' : "^("+ searchString + ")$", true, false )
    .draw()

    The above assumes that multiple search strings are concatenated with pipes (" | "), e.g. "A1|A3|C5 Hedged"

This discussion has been closed.