F
Filament2d ago
Iced

How to format a TextColumn

Hello, i need to remove html tags from a specific column.
TextColumn::make('body')
->label(__('Body'))
->searchable()
->visibleFrom('md'),
TextColumn::make('body')
->label(__('Body'))
->searchable()
->visibleFrom('md'),
How to remove the html tags from body ->formatStateUsing not working for me.
Solution:
or ```php use Filament\Tables\Columns\TextColumn; use Illuminate\Support\HtmlString;...
Jump to solution
22 Replies
Matthew
Matthew2d ago
That's weird... how did you use it?
toeknee
toeknee2d ago
->html()
Iced
IcedOP2d ago
wait oh, nice. How to remove tags then?
Matthew
Matthew2d ago
Try this:
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;

TextColumn::make('description')
->formatStateUsing(fn (string $state) => strip_tags($state))
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;

TextColumn::make('description')
->formatStateUsing(fn (string $state) => strip_tags($state))
Iced
IcedOP2d ago
I have Html and want to remove from html the tags. format into text Yep this is how i tested, not working.
Matthew
Matthew2d ago
Can you show us what you tried?
toeknee
toeknee2d ago
the above will only work if you have done html
Iced
IcedOP2d ago
TextColumn::make('body')
->formatStateUsing(fn (string $state) => strip_tags($state)),
TextColumn::make('body')
->formatStateUsing(fn (string $state) => strip_tags($state)),
No description
Iced
IcedOP2d ago
always html tags there
toeknee
toeknee2d ago
try:
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;

TextColumn::make('description')
->formatStateUsing(fn (string $state) => strip_tags(html_entity_decode($state)))
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;

TextColumn::make('description')
->formatStateUsing(fn (string $state) => strip_tags(html_entity_decode($state)))
Iced
IcedOP2d ago
also this.
Solution
toeknee
toeknee2d ago
or
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;

TextColumn::make('description')
->html()
->formatStateUsing(fn (string $state) => strip_tags($state))
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;

TextColumn::make('description')
->html()
->formatStateUsing(fn (string $state) => strip_tags($state))
Iced
IcedOP2d ago
also not working.
Iced
IcedOP2d ago
No description
Iced
IcedOP2d ago
all time this result.
Iced
IcedOP2d ago
No description
toeknee
toeknee2d ago
strip_tags(html_entity_decode($state))
strip_tags(html_entity_decode($state))
Id you dd($state) does it get hit?
Iced
IcedOP2d ago
nop dd not hitted. ->formatStateUsing(fn (string $state) => dd($stae)), do nothing
toeknee
toeknee2d ago
Sounds like you have cached it or somehting, as format state should be hit
Iced
IcedOP2d ago
hm ok
toeknee
toeknee2d ago
php artisan optimize:clear
Iced
IcedOP2d ago
not helped. also the issue no dd i will debug wait fixed. thx

Did you find this page helpful?