How to use TextColumn instead of SelectColumn?

Hi all, I am new to filament, started looking at it last week. Can you please help, I basically want to display TextColum instead of SelectColumn based on this? public static function table(Table $table): Table { return $table ->columns([ SelectColumn::make('status') ->options([ '0' => 'Draft', '1' => 'Complete', '2' => 'Incomplete', ]) Would you be able to advise please, much appreciated. thanks #TextColumn #SelectColumn
Solution:
```php TextColumn::make('status') ->formatStateUsing(function(string $state) { return match($state) { '1' => 'Complete',...
Jump to solution
7 Replies
Dennis Koch
Dennis Koch13mo ago
Can you please help, I basically want to display TextColum instead of SelectColumn based on this?
And what's the issue with that? The translation from ID to Value? Then see Leandros answers.
maxtor831
maxtor831OP13mo ago
yes, the translation from ID to Value, I am basically trying filament, there is a big project that I would like to use it for, I want to make sure that I am not limited by custom functionality thank you, how would you translate ID to Values in here? Tables\Columns\TextColumn::make('status') ->formatStateUsing(fn (string $state): string => __("statuses.{$state}")) If I understood right, you suggesting to have a translation value stored for statuses.1 = 'Draft' , this seems a bit hacky, I do like the idea how its done on SelectColumn::make('status') ->options([ '0' => 'Draft', '1' => 'Complete', '2' => 'Incomplete', ]) wouldn't something like this work for TextColumn?
awcodes
awcodes13mo ago
Yes. Just use a match against the state and return your value. However, this would be a lot easier with an enum.
maxtor831
maxtor831OP13mo ago
Hi, thanks, would you have a sample for this please? Not too sure if you said yes to have translations or if something like the above would work for TextColumn.
Solution
awcodes
awcodes13mo ago
TextColumn::make('status')
->formatStateUsing(function(string $state) {
return match($state) {
'1' => 'Complete',
'2' => 'Incomplete',
default => 'Draft',
};
})
TextColumn::make('status')
->formatStateUsing(function(string $state) {
return match($state) {
'1' => 'Complete',
'2' => 'Incomplete',
default => 'Draft',
};
})
For enums see https://filamentphp.com/docs/3.x/support/enums
maxtor831
maxtor831OP13mo ago
Works like a charm, thank you!
Want results from more Discord servers?
Add your server