F
Filamentβ€’10mo ago
Dushmanta

How can I keep an icon in the column label instead of text in the table?

I'm trying to implement a table, and in one column, I want an icon instead of a text label. Can anyone help me with this? Thank you.
Solution:
```php TextColumn::make('status') ->label(view('test-dummy')) ...
Jump to solution
8 Replies
LeviBeezy
LeviBeezyβ€’10mo ago
According to the docs, you might want the Icon Column for Tables https://filamentphp.com/docs/3.x/tables/columns/icon
Dushmanta
DushmantaOPβ€’10mo ago
IconColumn::make('plus')
->icon('heroicon-o-plus')
IconColumn::make('plus')
->icon('heroicon-o-plus')
I've done that like this but in the label Plus shows but I want the icon to appear
LeviBeezy
LeviBeezyβ€’10mo ago
IconColumn::make('status')
->icon('heroicon-o-plus')
->color(fn (string $state): string => match ($state) {
'Default' => 'secondary',
'Subscribed' => 'success',
'Unsubscribed' => 'danger',
'Engaged' => 'success',
'Inactive' => 'warning',
'Bounced' => 'warning',
'Complaint' => 'danger',
'Pending Verification' => 'info',
})
->toggleable(true),
IconColumn::make('status')
->icon('heroicon-o-plus')
->color(fn (string $state): string => match ($state) {
'Default' => 'secondary',
'Subscribed' => 'success',
'Unsubscribed' => 'danger',
'Engaged' => 'success',
'Inactive' => 'warning',
'Bounced' => 'warning',
'Complaint' => 'danger',
'Pending Verification' => 'info',
})
->toggleable(true),
No description
LeviBeezy
LeviBeezyβ€’10mo ago
I have a field 'status' in my model
Dushmanta
DushmantaOPβ€’10mo ago
Yes! I want an icon instead of that Status text, so I'm wondering if it's possible.
Solution
dissto
disstoβ€’10mo ago
TextColumn::make('status')
->label(view('test-dummy'))

// test-dummy.blade.php
<x-filament::icon icon="heroicon-o-user" class="w-5 h-5"/>
TextColumn::make('status')
->label(view('test-dummy'))

// test-dummy.blade.php
<x-filament::icon icon="heroicon-o-user" class="w-5 h-5"/>
Or as an alternative approach without a view
TextColumn::make('status')
->label(function () {
return new HtmlString(Blade::render('<x-filament::icon icon="heroicon-o-user" class="w-5 h-5" />'));
})
TextColumn::make('status')
->label(function () {
return new HtmlString(Blade::render('<x-filament::icon icon="heroicon-o-user" class="w-5 h-5" />'));
})
Thats one way. But please have accessibility in mind πŸ’ͺ
dissto
disstoβ€’10mo ago
No description
Dushmanta
DushmantaOPβ€’10mo ago
Woahh! That worked, Thanks a lot. 🀜 πŸ€› both worked πŸ™‚ Thanks a lot @dissto I really appreciate the help πŸ™‚

Did you find this page helpful?