Sanity check: is this the correct way to filter a column for NULL value?

Sanity check: is this the correct way to filter a column for NULL value?

hwyckoffhwyckoff Posts: 19Questions: 7Answers: 1

I am using the following code block to dynamically filter a specific column in a table based on selections made in a select control.

The code works, but I wanted to make sure I wasn't missing out on a simpler and obvious way to search by array with the possibility of null selections. I didn't see anything on Stack Overflow or this forum by the search terms used, so I figured this might add to the pool of useful questions.

Is there more efficient way to make this search, or is this as good as it gets?

                /* indended behavior: if no options are checked in select list, 
                 *  search for null value in column
                */

                var codes = "(?=.*" + latestExitCode.val().join('|') + ")";

                if (codes === "(?=.*)") {
                    console.log("Empty codes");
                    t.column(5).search(null).draw();
                } else {
                    t.column(5).search(codes, true, false, false).draw();
                }

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    All of the searches that DataTables' built in filtering code uses are string based. There isn't a strict null option other than to use a custom search plug-in I'm afraid.

    Allan

This discussion has been closed.