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?
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
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