F
Filament12mo ago
Mellor

Using `icons` with IconColumn

Hi, I'm just playing with the Table Builder and using the User model for example. I was looking at using the IconColumn on the email_verified_at column, to show if it is verified or not. I think this class is better suited to a boolean field, but just trying it out. I saw the options method was deprecated (though no mention of that in the docs) and saw it recommended to use icons instead. I tried:
IconColumn::make('email_verified_at')
->label('Email verified?')
->icons(fn ($record) => [
'heroicon-o-x-mark' => is_null($record->email_verified_at),
'heroicon-o-check-circle' => ! is_null($record->email_verified_at),
]),
IconColumn::make('email_verified_at')
->label('Email verified?')
->icons(fn ($record) => [
'heroicon-o-x-mark' => is_null($record->email_verified_at),
'heroicon-o-check-circle' => ! is_null($record->email_verified_at),
]),
But I get no icons. I also tried with the icon method and a ternary operator
->icon(fn ($record) => is_null($record->email_verified_at) ? 'heroicon-o-x-mark' : 'heroicon-o-check-circle'),
->icon(fn ($record) => is_null($record->email_verified_at) ? 'heroicon-o-x-mark' : 'heroicon-o-check-circle'),
This gets me a bit further and shows the ✅ but not the ❌ Perhaps I'm missing something? Thanks.
5 Replies
awcodes
awcodes12mo ago
Maybe ->icon(fn($state) => $state ? ‘heroicon-o-x-mark’ : ‘heroicon-o-check-circle’) Switch the icons. Sorry.
Mellor
Mellor12mo ago
No, I still don't get an image for the false value.
awcodes
awcodes12mo ago
Can you dd the $state to see what it’s outputting? It may not be coming back as null for some reason.
ImShehryar
ImShehryar12mo ago
Not works with me also: Tables\Columns\IconColumn::make('email_verified_at') ->label('Email Verified') ->icon(fn($state) => $state ? 'heroicon-o-check-circle' : 'heroicon-o-x-circle') ->sortable(),
vkDas
vkDas8mo ago
Have you resolved it ?