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 Koch2y ago
They are both using formatStateUsing() under the hood so they overwrite each other. Check the code of both methods and combine them
awcodes
awcodes2y 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
Homd15mo 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
bionary11mo 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'))

Did you find this page helpful?