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:Jump to solution
```php
TextColumn::make('status')
->formatStateUsing(function(string $state) {
return match($state) {
'1' => 'Complete',...
7 Replies
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.
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?
Yes. Just use a match against the state and return your value.
However, this would be a lot easier with an enum.
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
Works like a charm, thank you!