F
Filamentβ€’2w ago
ericmp

How to set tooltip on table header?

I want to be able to set a tooltip on the table header. Is there any way to achieve it for now? Or I might have to implement it by myself? Im trying to search if there is a way to do it. For now, havent found it. The screenshot would be what i want to achieve.
No description
11 Replies
ericmp
ericmpOPβ€’2w ago
i guess yeah im trying to set it up but, what is $this on this context?
No description
ericmp
ericmpOPβ€’2w ago
TextColumn::macro('abbr', function (?string $abbr = null, bool $asTooltip = false) {
$label = $this->getLabel();
$abbr = $abbr ?? $label;
$classes = $this->isSortable() ? 'cursor-pointer' : 'cursor-help';

$attributes = $asTooltip ? 'x-tooltip.raw="'.$abbr.'" title=""' : 'title="'.$abbr.'"';

return $this->label(new HtmlString("<abbr class=\"$classes\" $attributes>$label</abbr>"));
});
TextColumn::macro('abbr', function (?string $abbr = null, bool $asTooltip = false) {
$label = $this->getLabel();
$abbr = $abbr ?? $label;
$classes = $this->isSortable() ? 'cursor-pointer' : 'cursor-help';

$attributes = $asTooltip ? 'x-tooltip.raw="'.$abbr.'" title=""' : 'title="'.$abbr.'"';

return $this->label(new HtmlString("<abbr class=\"$classes\" $attributes>$label</abbr>"));
});
(i shared it as img so u see the red underline)
dissto
disstoβ€’2w ago
This is just how macros work. $this will get bound to the instance you access it on. So $this is the TextColumn in that case. See the collection example from the laravel docs
ericmp
ericmpOPβ€’2w ago
yeah i see its not crashing, just my code editor but its not working, what im missing? im just adding it in the boot method as u say and then
Tables\Columns\TextColumn::make('club.name')->abbr('random', true)
Tables\Columns\TextColumn::make('club.name')->abbr('random', true)
but i cannot see any toolitps when hovering i also added the item to the safelist and ran npm run build (btw thanks for the link to the docs, im reading them now)
dissto
disstoβ€’2w ago
Can you try putting ->abbr() at the end as last method?
ericmp
ericmpOPβ€’2w ago
ahhh i see, yeah makes sense, must be called after calling ->label() it worksssss thanks @dissto appreciate ur post on filamentglow and now ur further help here! πŸ™ also thanks leandro for pointing out the trick! πŸ™Œ
ericmp
ericmpOPβ€’2w ago
@dissto not sure if u knew it (i guess yeah), but i share it to u: if the ide struggles trying to understand the context of this, u can do this:
/** @var \Filament\Tables\Columns\Column $this */
$this;
/** @var \Filament\Tables\Columns\Column $this */
$this;
now it doesnt underline any error (:
No description
ericmp
ericmpOPβ€’2w ago
u knew it?
dissto
disstoβ€’2w ago
yea its good, maybe I can edit my trick πŸ€“
ericmp
ericmpOPβ€’2w ago
cool (;
Want results from more Discord servers?
Add your server