Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filamentβ€’3y agoβ€’
1 reply
Arnaud

Add dynamic columns in table

Hello,

Not help but maybe somebody can find it when searching.

I was looking to add some columns to my table. I have a resource who has many states. The states can be created dynamically from the database and in my case the relation is MorphToMany πŸ˜…

But easy to add it to Filament :

1/ Add the getTableColumns() function
2/ Inside, push new columns to exist ones
$columns = [
  // others columns I've already created
];

foreach ($this->stages as $stage) {
  $columns[] = TextColumn::make('stages.['.$stage->id.'].name')
    ->label($stage->name)
    ->placeholder('-')
    ->toggleable(isToggledHiddenByDefault: true)
    ->state(function ($record) use ($stage) {
        $selectedStage = $record->stages->where('id', $stage->id)->first();

        if (! $selectedStage) { return; }
        return $selectedStage->pivot->created_at->format('d/m/Y');
  });
}

return $columns;
$columns = [
  // others columns I've already created
];

foreach ($this->stages as $stage) {
  $columns[] = TextColumn::make('stages.['.$stage->id.'].name')
    ->label($stage->name)
    ->placeholder('-')
    ->toggleable(isToggledHiddenByDefault: true)
    ->state(function ($record) use ($stage) {
        $selectedStage = $record->stages->where('id', $stage->id)->first();

        if (! $selectedStage) { return; }
        return $selectedStage->pivot->created_at->format('d/m/Y');
  });
}

return $columns;

Enjoy
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel β€’ Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

columns dynamic inside table
FilamentFFilament / β“β”Šhelp
3y ago
Repeater "Table" with dynamic columns
FilamentFFilament / β“β”Šhelp
8mo ago
Dynamic Customise Columns for Table
FilamentFFilament / β“β”Šhelp
2y ago
TablesRenderHook after table filter / toggle columns
FilamentFFilament / β“β”Šhelp
6mo ago