F
Filament2mo ago
xxx

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
Matthew2mo ago
That's weird... how did you use it?
toeknee
toeknee2mo ago
->html()
xxx
xxxOP2mo ago
wait oh, nice. How to remove tags then?
Matthew
Matthew2mo 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))
xxx
xxxOP2mo ago
I have Html and want to remove from html the tags. format into text Yep this is how i tested, not working.
Matthew
Matthew2mo ago
Can you show us what you tried?
toeknee
toeknee2mo ago
the above will only work if you have done html
xxx
xxxOP2mo ago
TextColumn::make('body')
->formatStateUsing(fn (string $state) => strip_tags($state)),
TextColumn::make('body')
->formatStateUsing(fn (string $state) => strip_tags($state)),
No description
xxx
xxxOP2mo ago
always html tags there
toeknee
toeknee2mo 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)))
xxx
xxxOP2mo ago
also this.
Solution
toeknee
toeknee2mo 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))
xxx
xxxOP2mo ago
also not working.
xxx
xxxOP2mo ago
No description
xxx
xxxOP2mo ago
all time this result.
xxx
xxxOP2mo ago
No description
toeknee
toeknee2mo ago
strip_tags(html_entity_decode($state))
strip_tags(html_entity_decode($state))
Id you dd($state) does it get hit?
xxx
xxxOP2mo ago
nop dd not hitted. ->formatStateUsing(fn (string $state) => dd($stae)), do nothing
toeknee
toeknee2mo ago
Sounds like you have cached it or somehting, as format state should be hit
xxx
xxxOP2mo ago
hm ok
toeknee
toeknee2mo ago
php artisan optimize:clear
xxx
xxxOP2mo ago
not helped. also the issue no dd i will debug wait fixed. thx

Did you find this page helpful?