Null state for table column

Hello, I have a column in my project that is nullable, I'm trying to make a default display value for it but I'm not finding a way. This is what I'm trying to do:
TextColumn::make('transaction.amount')
->label('Received Amount')
->placeholder('N/A'),
TextColumn::make('transaction.amount')
->label('Received Amount')
->placeholder('N/A'),
4 Replies
Miguilim
MiguilimOP17mo ago
Unfortunately not, I tried:
->formatStateUsing(fn (?int $state): int => $state ?? 'N/A'),
->formatStateUsing(fn (?int $state): int => $state ?? 'N/A'),
But it seems the column does not use this method if there is no value
awcodes
awcodes17mo ago
$state will always be mixed. And you’re telling the callback to return an int, but also trying to return a string of it is null.
->formatStateUsing(fn ($state): int|string => $state ?? 'N/A'),
->formatStateUsing(fn ($state): int|string => $state ?? 'N/A'),
If you’re on v3 you could use ->default(‘N/A’)
Miguilim
MiguilimOP17mo ago
Sorry I sent the wrong example, the return was int|string This worked! Thanks! I was only trying with formatStateUsing 😅
Want results from more Discord servers?
Add your server