F
Filament12mo ago
Anik

Display labels on table grid

Hi, is there a way to display labels on a table grid with component stacks. The table label are auto hidden on layout grid. It would be best if we had a way to toggle the display of labels on a table grid.
8 Replies
Anik
AnikOP12mo ago
the labels can be somewhat like the infolist textentry
Daniel
Daniel12mo ago
i'm also interested in this
Anik
AnikOP12mo ago
I can work on a PR if this feature will be supported bump
awcodes
awcodes12mo ago
The best approach would be to format the state of the field. There's no way for Filament to know how you want to present the data when it's used in a stack / grid. This is what I tend to do:
->formatStateUsing(function ($state) {
return 'Label: ' . $state;
})
->formatStateUsing(function ($state) {
return 'Label: ' . $state;
})
Daniel
Daniel12mo ago
define a macro (in a service provider):
Column::macro('formatSateUsingLabelPrefix', function() {
return $this->formatStateUsing(function(Column $column, $state) {
return $column->getLabel() . ': ' . $state;
});
});
Column::macro('formatSateUsingLabelPrefix', function() {
return $this->formatStateUsing(function(Column $column, $state) {
return $column->getLabel() . ': ' . $state;
});
});
and then:
TextColumn::make('my_field')
->label('My label')
->formatSateUsingLabelPrefix();
TextColumn::make('my_field')
->label('My label')
->formatSateUsingLabelPrefix();
Anik
AnikOP12mo ago
That is true. Thank you for your response. The best and cleanest approach imho would be to have a displayLabels() method on the Stack::class as it's the one hiding the labels and display the labels like the infolists to keep same UI. That way it can be an optional additional feature.
tim.lalev
tim.lalev12mo ago
Old thread but here is another trick for whoever may be looking this up: the description still works as expected and accepts position ( above, below ) as argument: TextColumn::make('my_field')->description('Label','above');
Anik
AnikOP12mo ago
most plausible solution for now

Did you find this page helpful?