searchable method makes columns all same width

How do I prevent bool values from taking up so much space? It's adding horizontal scroll to the table now because of this.
No description
10 Replies
idk
idk3w ago
Hi, maybe try to add ->extraAttributes(['style' => 'width: desired width']) to the column see if it works.
Fossil
FossilOP3w ago
Tried that. No go. Seems like the width is decided higher up in the HTML 😦
idk
idk3w ago
Can you share the code?
Fossil
FossilOP3w ago
Every column is same=ish width
No description
Fossil
FossilOP3w ago
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('username')->searchable(isIndividual: true, isGlobal: false),
TextColumn::make('email')->searchable(isIndividual: true, isGlobal: false),
TextColumn::make('roles.name')->label('Role'),
TextColumn::make('lastlogin')->dateTime('d-m-Y H:i:s')->label('Last Login'),
TextColumn::make('apiaccess')->dateTime('d-m-Y H:i:s')->label('Last API'),
IconColumn::make('verified')->boolean(),
IconColumn::make('bad_user')->boolean()->label('Bad User'),
IconColumn::make('passwordsecurity.google2fa_enable')->boolean()->label('2FA')->default(0),
])
->filters(
[

],
layout: \Filament\Tables\Enums\FiltersLayout::AboveContent,
)
->actions([
Tables\Actions\ViewAction::make()->slideOver(),
Tables\Actions\EditAction::make()->slideOver()->after(function (User $record, Role $role) {
$record->syncRoles($record->role->name);
$role = $role->findByName($record->role->name);
$record->givePermissionTo($role->findByName($record->role->name, null)->permissions->pluck('name'));
}),
Tables\Actions\Action::make('disable')
->label('2FA')
->action(fn (User $record) => $record->disable2FA())
->requiresConfirmation()
->icon('heroicon-o-lock-closed')
->color('danger'),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make()
->requiresConfirmation(),
]);

}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('username')->searchable(isIndividual: true, isGlobal: false),
TextColumn::make('email')->searchable(isIndividual: true, isGlobal: false),
TextColumn::make('roles.name')->label('Role'),
TextColumn::make('lastlogin')->dateTime('d-m-Y H:i:s')->label('Last Login'),
TextColumn::make('apiaccess')->dateTime('d-m-Y H:i:s')->label('Last API'),
IconColumn::make('verified')->boolean(),
IconColumn::make('bad_user')->boolean()->label('Bad User'),
IconColumn::make('passwordsecurity.google2fa_enable')->boolean()->label('2FA')->default(0),
])
->filters(
[

],
layout: \Filament\Tables\Enums\FiltersLayout::AboveContent,
)
->actions([
Tables\Actions\ViewAction::make()->slideOver(),
Tables\Actions\EditAction::make()->slideOver()->after(function (User $record, Role $role) {
$record->syncRoles($record->role->name);
$role = $role->findByName($record->role->name);
$record->givePermissionTo($role->findByName($record->role->name, null)->permissions->pluck('name'));
}),
Tables\Actions\Action::make('disable')
->label('2FA')
->action(fn (User $record) => $record->disable2FA())
->requiresConfirmation()
->icon('heroicon-o-lock-closed')
->color('danger'),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make()
->requiresConfirmation(),
]);

}
They are all 192px
idk
idk3w ago
Have you tried something like this?
No description
Fossil
FossilOP3w ago
Tried both yeah No changes
idk
idk3w ago
Mmm no idea then. Wait until someone from the core team replies to you
Fossil
FossilOP3w ago
Cheers Width does add the style to the <th> but it stays at 192px for some reason ->compact() would be nice to have on a table Looks like when I remove the search box row from the HTML the columns actually srhinks down a lot ->searchable(isIndividual: true, isGlobal: false) ->searchable(isIndividual: true, isGlobal: false) Yeah, removing this from columns makes the table super condensed. And each column is a different size now.
idk
idk3w ago
Damn didnt know that

Did you find this page helpful?