I need SelectFilter with no relationship to show null values to choose from
Hello. I have a resource with a field called 'group' which is NOT a relationship and user can type whatever they want (string). And I need o add a filter to let them choose from all the different variations in the column. I already get a good result with that, but I do not know hot to ADD the option to choose THE NULL ones, I mean, if you choose group 'IV' it works, but I can not choose "blank ones" o "unset" (regarding the column 'group' which is nullable)
My filter at the moment is:
It also shows strange valued such as 0 (Zero) but no record has a Zero in that column.
Any ideas of how to make a filter to let user choose from any differente value in one column including a filter for the unset o null ones?
Tks.
6 Replies
Because you pass array in array.
remove these brackets
->options([
must be like this -
also you can write it shortly
Thank you for the tip. I removed the first pair or brackets and now it shows all values correctly without strange zeros above. But, anyway, I would like to have the unset ones (the null ones) to choose from. I mean, if there are three variations in the records (1,2,3) but there are also records with a blank value in that field, I would like to be able to choose the blank ones also, besides every different value.
Is that possible?
aren't empty records currently in the select options?
No
Anyway, I have thought of a way to change the content of the column called 'group' retrieving the group if there is anything written or 'empty' if it is null. That way I could filter by all the values including the empty string value.
But when I change the getEloquentQuery(): Builder it throws an error ==> Return value must be of type Illuminate\Database\Eloquent\Builder, Illuminate\Support\Collection returned
My code is:
How can I do that???
I would need to change the query (the column value with a ternary if statement).
Tks.
Now, with this function:
I can change the column data when it is retrieved, which is fantastic, but nothing happens in the filter.
The
getEloquentQuery
method only to modify the query.
Use the formatStateUsing
method on your column - https://filamentphp.com/docs/3.x/tables/columns/text#custom-formatting
Examples:
Right. Thank you. But then the filter is not aware of this changes, so I still cannot filter by the null ones, and not even the search is aware of these changes.