column.search() blank values

column.search() blank values

Rothrock42Rothrock42 Posts: 7Questions: 3Answers: 0

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

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394
    edited January 2019

    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.

  • Rothrock42Rothrock42 Posts: 7Questions: 3Answers: 0

    All I had to do was ask and then I found the answer myself!

    This thread includes the solution.

    table.columns($ref).search('^$',true,false).draw()
    

    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.

  • allanallan Posts: 61,442Questions: 1Answers: 10,053 Site admin

    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 a filter() 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

  • Rothrock42Rothrock42 Posts: 7Questions: 3Answers: 0

    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!

This discussion has been closed.