F
Filament15mo ago
lukevi

Set all column titles to headline()

Hi- I have lots of two-word column names, and I'd prefer table columns to use headline case, eg "Created At" rather than the default which winds up as "Created at". I know I could set an explicitly-cased title for each one, but I would much prefer that as the default. Is there any place I can override getLabel() for my project? This tweak solves it:
public function getLabel(): string | Htmlable
{
$label = $this->evaluate($this->label) ?? (string) str($this->getName())
->beforeLast('.')
->afterLast('.')
->headline();
// ->kebab()
// ->replace(['-', '_'], ' ')
// ->ucfirst();
public function getLabel(): string | Htmlable
{
$label = $this->evaluate($this->label) ?? (string) str($this->getName())
->beforeLast('.')
->afterLast('.')
->headline();
// ->kebab()
// ->replace(['-', '_'], ' ')
// ->ucfirst();
4 Replies
lukevi
lukeviOP15mo ago
I see that a prior post here has made a similar change to resource titles. [https://github.com/filamentphp/filament/pull/3873] I would be happy to make a similar PR for this change if people agree this would be a preferable default!
awcodes
awcodes15mo ago
A PR for this wouldn’t get merge in my opinion. If you need to do something globally see https://filamentphp.com/docs/3.x/tables/columns/getting-started#global-settings
lukevi
lukeviOP15mo ago
Ahh thank you - a global setting will go a long way toward solving this for me. I'll try this now. This framework continues to amaze. That suggestion worked perfectly, thanks again. Full context in case it helps anyone else:
// added in MyPanelProvider:
public function boot()
{
Column::configureUsing(function (Column $column): void {
$column->label(
str($column->getName())
->beforeLast('.')
->afterLast('.')
->headline()
);
});
}
// added in MyPanelProvider:
public function boot()
{
Column::configureUsing(function (Column $column): void {
$column->label(
str($column->getName())
->beforeLast('.')
->afterLast('.')
->headline()
);
});
}
The casing change even applied in the panel's TableWidget, and does not interfere with any explicitly set titles.
lukevi
lukeviOP14mo ago
Tacking on to my own old question since I've wound up adding the same tweak to form field names:
// now in AppServiceProvider instead of adding to each individual Filament/PanelProvider

// Labels like 'Head Line' not 'Head line':
$overrideDefaultLabel = function (Field|Column $o): void {
$o->label(
str($o->getName())
->beforeLast('.')
->afterLast('.')
->headline()
);
};

Column::configureUsing($overrideDefaultLabel);
Field::configureUsing($overrideDefaultLabel);
// now in AppServiceProvider instead of adding to each individual Filament/PanelProvider

// Labels like 'Head Line' not 'Head line':
$overrideDefaultLabel = function (Field|Column $o): void {
$o->label(
str($o->getName())
->beforeLast('.')
->afterLast('.')
->headline()
);
};

Column::configureUsing($overrideDefaultLabel);
Field::configureUsing($overrideDefaultLabel);
Want results from more Discord servers?
Add your server