IconColumn display error v3
If you try to map a JSON table value using IconColumn, the icon is mapped/displayed x-fold (per array item) if values are available.
11 Replies
any ideas?
maybe your code
IconColumn::make('allowed_user_ids')
->label(__('Users'))
->toggleable()
->icon(fn (string $state): string => match ($state) {
'' => 'heroicon-o-minus',
default => 'heroicon-o-user-group'
})
Based on your code what you receive/display in tables were correct.
ok - but allowed_user_ids is ja JSON Field, why they output not only one icon then?
and you see also that a empty state don't return a minus icon
What are you trying to do? if
allowed_user_ids
is not null then display "user-group" otherwise "minus"?right, but in V2 they show only one user-group icon and a minus if the value is empty, now they show x-icons based on the array length
@Dan Harrin Could it be that JSON (array cast fields) might need a special parameter, in v2 it was displayed normally?
"normal" IMO is what we have in v3
otherwise JSON is not supported at all
you can use getStateUsing() to transform the allowed_user_ids into another value which you can use in the icon
OR you can get the $record in icon() and decide the icon based on that instead of the raw state
I haven't found anything about getStateUsing in the docs - is there an alternative to the doc to solve such problems myself?
just an alias for this method