Search Using a RegExp Object

Search Using a RegExp Object

tech-otakutech-otaku Posts: 2Questions: 1Answers: 0

I'm using the following code to search for blank cells in a specific column:

column.search('^$', {
    regex: true,
    exact: false,
    smart: false
}).draw();

It works, but this documentation states that;

Note that as of DataTables 2.0 this option is discouraged - if you wish to perform a regular expression search, pass the search term in as a RegExp object (rather than a string with a regex in it).

I've found forum posts where the RegExp object is used, but I'm struggling to understand how to convert my code to use said object as there doesn't appear to be any documentation on using it - apologies if I've somehow missed it!

I'd be grateful if someone could point me in the right direction.

Many thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,365Questions: 1Answers: 10,627 Site admin
    Answer ✓

    columns.search(/^$/).draw() should do it.

    Allan

  • tech-otakutech-otaku Posts: 2Questions: 1Answers: 0

    @allan

    columns.search(/^$/).draw()

    Perfect. Thank you.

  • allanallan Posts: 64,365Questions: 1Answers: 10,627 Site admin
    edited May 11

    I should probably mention that doesn't work for server-side processing. Very much a client-side search action that. (Just in case anyone else finds this thread :)).

    Allan

Sign In or Register to comment.