F
Filamentβ€’2mo ago
Tim

Condensed tables

I was working on a way to make more condensed tables because I have some 800 row tables (I know!). I found that adding this macro to my provider:
Table::macro('condensed', function (string $class = 'fi-table-condensed'): Table {
/** @var Table $this */
$existing = $this->getExtraAttributes()['class'] ?? '';

$this->extraAttributes([
'class' => trim("{$existing} {$class}"),
]);

return $this;
});
Table::macro('condensed', function (string $class = 'fi-table-condensed'): Table {
/** @var Table $this */
$existing = $this->getExtraAttributes()['class'] ?? '';

$this->extraAttributes([
'class' => trim("{$existing} {$class}"),
]);

return $this;
});
And then the following CSS to my theme:
@layer components {
.fi-table-condensed .fi-ta-text:not(.fi-inline) {
padding-inline: 0.5rem !important; /* px-2 */
padding-block: 0.25rem !important; /* py-1 */
}
}
@layer components {
.fi-table-condensed .fi-ta-text:not(.fi-inline) {
padding-inline: 0.5rem !important; /* px-2 */
padding-block: 0.25rem !important; /* py-1 */
}
}
Then in my tables I could just use condensed eg:
public static function configure(Table $table): Table
{
return $table
->condensed()
->columns([
TextColumn::make('name')
]);
}
public static function configure(Table $table): Table
{
return $table
->condensed()
->columns([
TextColumn::make('name')
]);
}
Hope it might be useful - or if I did this wrong and there's a better way please let me know!
5 Replies
Dennis Koch
Dennis Kochβ€’2mo ago
Nice tip. Maybe format your code to make it more readable.
Tim
TimOPβ€’2mo ago
thanks dennis! can you tell I am a newbie on discord? πŸ˜‚
Dennis Koch
Dennis Kochβ€’2mo ago
Looks like you figured it out πŸ˜…
Liam
Liamβ€’2mo ago
@Tim I think your code block cut off, but presumably it's meant to be something like:
Table::macro('condensed', function (string $class = 'fi-table-condensed'): Table {
/** @var Table $this */
$existing = $this->getExtraAttributes()['class'] ?? '';

$this->extraAttributes([
'class' => trim("{$existing} {$class}"),
]);

return $this;
});
Table::macro('condensed', function (string $class = 'fi-table-condensed'): Table {
/** @var Table $this */
$existing = $this->getExtraAttributes()['class'] ?? '';

$this->extraAttributes([
'class' => trim("{$existing} {$class}"),
]);

return $this;
});
Tim
TimOPβ€’2mo ago
sorry I missed this Liam! you are completely right

Did you find this page helpful?