SearchCols requires un-documented option to use regex

SearchCols requires un-documented option to use regex

dom_woodmandom_woodman Posts: 2Questions: 1Answers: 0

I wanted to initialise a datatable using "searchCols" and regex to define an exact match (i.e. "^cars$").

default_filters = [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    { search: "^car$", escapeRegex: false }
];

However this didn't work. On inspecting a fully created filter I spotted you could set the two options documented in search(), regex and smart with bRegex and bSmart.

The following filters worked correctly, but this isn't documented anywhere and assuming this is the intended solution it would be good to add to the official documentation.

default_filters = [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    { search: "^car$", bRegex: true, bSmart: false}
];

Version: https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Thanks for letting me know about that. That's an issue with the backwards compatibility for the Hungarian notation. What happens is that it actually maps the camelCase parameters to the legacy Hungarian ones (otherwise I would have needed to completely rewrite DataTables and also break backwards compatibility!).

    It looks like it isn't being applied to the parameters in the search columns array. I've logged it and will address that.

    Moreover, the plan is to move the search column information into the columns array with v2. The current option is a bit unintuitive.

    Allan

  • dom_woodmandom_woodman Posts: 2Questions: 1Answers: 0

    Aah ok that makes more sense. I was looking into this further recently and it seemed like sometimes setting it to search didn't map as intended, so I ended up setting it to sSearch.

    Also I had not come across Hungarian notation before, so that makes a lot more sense now. I could not follow the old naming convention. Thank you!

  • faniefanie Posts: 3Questions: 1Answers: 0

    Thank you! I wasn't able to understand why my filter didn't do his job correctly.
    Now, I use 'bRegex' and everything is ok :)

This discussion has been closed.