Filament Table Null Value: formatStateUsing() Doesn't Work?

In Filament tables, some values could be null, but you may want to still show some placeholder instead? A typical formatStateUsing() method wouldn't work. Let me show two alternatives.

Usually, when formatting the state, you would use the formatStateUsing() method:

TextColumn::make('status')
->formatStateUsing(fn (string $state): string => __("statuses.{$state}"))

But when the $state is null, the formatStateUsing() method is not executed. There are two ways to deal with this case.


Option 1: default()

The first way is to use the default() method on the column.

Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('description')
->default('No description'),

When using this method, Filament treats it as a state and also sets columns like image or color with the default values. This is different from the second alternative - placeholder.


Option 2: placeholder()

The second option is to add a placeholder.

Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('description')
->placeholder('No description'),

Placeholder has a lighter gray text color and isn't treated as a state.


If you want more Filament examples, you can find more real-life projects on our FilamentExamples.com.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 60 courses (1084 lessons, total 42 h 44 min)
  • 80 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials