column.search() blank values
column.search() blank values
I have a table were we are listing some projects that we are working on. I have a column called "Claimed by" which shows who is going to be working each item. I've used this technique to add a search footer to search the individual column. This is great for finding the pieces assigned to specific people.
How can I use the same search to find the empty ones?
I've done the following to see the values in that column table.column(ref).data().unique().sort()
and I see that I have both empty string and null
values which should be returned in this search.
I tried table.column(ref).search("").draw()
but that just clears the search. And I tried the same with null
but it returns nothing.
In addition to the code to get results, I'm wondering is there an easy user interface to allow my users to quickly find the "emptys"?
Answers
The simplest thing would be to sort on that column and have the "empties" float to the top.
Otherwise I think youll need to write some custom search code.
All I had to do was ask and then I found the answer myself!
This thread includes the solution.
At least part of the solution. That regular expression matches entries with "start and end" with nothing in between. I haven't confirmed if it includes the nulls.
Now I just need to figure that out and how to give it affordance for my users.
Hi,
Yes indeed, that's spot on. The issue here is that technically DataTables doesn't actually do a "search" but rather a "filter" (its called
search()
in the API though, since there is also afilter()
method which can be used to reduce a result set!).I've thought about using a true search before, but the issue is really the default input box - there would be no way to distinguish between a search for empty data and no search since its just a string input (user can't easily enter
null
).Allan
Thanks for the response allan. In this specific case I used two special characters...
I used ! as the "not" with the column search to get empties/blanks.
I also used * as a "match something" to get all not blank values.
In both cases there is no need for users (in this case) to search for either of those characters by themselves. Not completely self evident, but this need had a small audience that could be trained to use that...and they were highly motivated because they needed to find empties!