html + limit in text column

Im trying to use html and limit words in a text column but it doesnot respect html format showing tags:
Tables\Columns\TextColumn::make('acciones')
->html()
->limit(10)
Tables\Columns\TextColumn::make('acciones')
->html()
->limit(10)
is there a way to use both?
Solution:
They are both using formatStateUsing() under the hood so they overwrite each other. Check the code of both methods and combine them
Jump to solution
4 Replies
Solution
Dennis Koch
Dennis Koch16mo ago
They are both using formatStateUsing() under the hood so they overwrite each other. Check the code of both methods and combine them
awcodes
awcodes16mo ago
I would highly recommend not doing this. If you limit the rendered HTML you are going to have problems with the HTML tags getting cut off, which will more than likely break your table layout.
Homd
Homd14mo ago
Sorry for reopening the thread. But I have case that I want to show the excerpt of the field but don't want it to show all the html tag (u know, it looks weird for the user). you can use this
urcolumn->formatStateUsing(fn (string $state) => __( preg_replace('/((\w+\s*){1,50}).*/', '$1...', strip_tags($state))))
urcolumn->formatStateUsing(fn (string $state) => __( preg_replace('/((\w+\s*){1,50}).*/', '$1...', strip_tags($state))))
which will strip any html tag and limit it by 50 words
bionary
bionary10mo ago
I'm limiting by words this way: (it's very readable 'cause it's the Laravel way!)
->formatStateUsing(fn($state) => Str::of($state)->stripTags()->words('5'))
->formatStateUsing(fn($state) => Str::of($state)->stripTags()->words('5'))
Want results from more Discord servers?
Add your server