F
Filament2mo ago
Carlos

Conditionally rendering an icon in TextColumn

I have a situation where the value of a cell could be "true" or anything else. How can I render an icon instead of text in a TextColumn, I tried this but it didn't work:
Tables\Columns\TextColumn::make('value')
->formatStateUsing( fn($state) => $state === 'true' ? new HtmlString(Blade::render('<x-filament::icon icon="heroicon-o-check" class="w-4 h-4"/>')) : $state ),
Tables\Columns\TextColumn::make('value')
->formatStateUsing( fn($state) => $state === 'true' ? new HtmlString(Blade::render('<x-filament::icon icon="heroicon-o-check" class="w-4 h-4"/>')) : $state ),
Thanks!
Solution:
ahh ok. Use TextColumn::make('value')->icon(fn($record) => $record->value === 'true' ? 'heroicon-o-check' : null)
Jump to solution
3 Replies
Carlos
Carlos2mo ago
Thanks for your response, as far I know, the IconColumn displays "only" icons, in this case I only need to render the icon when the value is "true", if the value is "Dog", "Apple" or "House" I need to display the String
Solution
LeandroFerreira
LeandroFerreira2mo ago
ahh ok. Use TextColumn::make('value')->icon(fn($record) => $record->value === 'true' ? 'heroicon-o-check' : null)
Want results from more Discord servers?
Add your server
More Posts