© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•13mo ago•
6 replies
Alexandre

Is it possible to display key : value in a TextColumn ?

Hi all,

is it possible for a
TextColumn
TextColumn
to display the key and the value when the DB field is an array?
TextColumn always returns a string without the keys.

I have that in my DB :

{"panel": "admin", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0"}
{"panel": "admin", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0"}


And I want to display that in my table :

• panel : admin
• user_agent : Mozilla/5.0 (Windows NT 10...

For that I try this :

TextColumn::make('properties')
 ->label('Détails')
 ->getStateUsing(fn($record) => $record->properties)
 ->listWithLineBreaks()
 ->bulleted()
 ->wrap()
 ->toggleable()
 ->html(),
TextColumn::make('properties')
 ->label('Détails')
 ->getStateUsing(fn($record) => $record->properties)
 ->listWithLineBreaks()
 ->bulleted()
 ->wrap()
 ->toggleable()
 ->html(),


But in the end all I get is this without the keys:

• admin
• Mozilla/5.0 (Windows NT 10...

If I DD $record->propreties, I get my array :

array:2 [▼ // xxx.php:175
  "panel" => "admin"
  "user_agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0"
]
array:2 [▼ // xxx.php:175
  "panel" => "admin"
  "user_agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0"
]


Thanks for your help 🙂

cf. : https://www.answeroverflow.com/m/1176827225736224838
How to show array key in TextColumn - Filament
Hi i have Variant model whre i save json in format like this {"Name":"Value"} and i'm casting it
    protected $casts = [
        'variant_attributes_json' => 'array',
    ];
    protected $casts = [
        'variant_attributes_json' => 'array',
    ];

How could i display key into textcolumn or other column?
Because if i put it into textCol it in state is only value
```php
Tables\Columns\TextColumn::make('v...
How to show array key in TextColumn - Filament
Solution
Hi, thanks for your help 🙂
Based on your solution, I managed to get the desired result with that:

TextColumn::make('properties')
  ->label('Détails')
  ->formatStateUsing(function ($record) {
      if (is_array($record->properties)) {
          $formattedState = '<ul class="list-disc">';
          foreach ($record->properties as $key => $value) {
              $formattedState .= "<li><strong>{$key} :</strong> {$value}</li>";
          }
          $formattedState .= '</ul>';

          return $formattedState;
      }

      return $record->properties;
  })
  ->wrap()
  ->toggleable()
  ->html(),
TextColumn::make('properties')
  ->label('Détails')
  ->formatStateUsing(function ($record) {
      if (is_array($record->properties)) {
          $formattedState = '<ul class="list-disc">';
          foreach ($record->properties as $key => $value) {
              $formattedState .= "<li><strong>{$key} :</strong> {$value}</li>";
          }
          $formattedState .= '</ul>';

          return $formattedState;
      }

      return $record->properties;
  })
  ->wrap()
  ->toggleable()
  ->html(),




->getStateUsing(fn($record) => $record->properties)
->getStateUsing(fn($record) => $record->properties)
method seems unnecessary in this case.
So everything's good, I just have the impression that it's not very clean, I don't know why. 😅

Anyway, thanks for everything 😉
result.png
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Is it possible to add a action on a textcolumn
FilamentFFilament / ❓┊help
3y ago
How to display an enum's label rather than value in a TextColumn?
FilamentFFilament / ❓┊help
3y ago
Is it possible to call a table action from a TextColumn cell?
FilamentFFilament / ❓┊help
3y ago
How to show array key in TextColumn
FilamentFFilament / ❓┊help
3y ago