F
Filamentβ€’5mo ago
benlumley

Is there a way to enable sortable on a column that is hidden?

I have a table that has a 'name' column; (in model; name concats first name and last name) TextColumn::make('name') ->searchable(['first_name', 'last_name']) ->sortable(['last_name']), However, requirement has come in to enable sorting by first name or last name? I was thinking I'd add first name and last name as separate columns, enable sortable and hide them. But you can't sort by hidden columns. (Table uses a split - so has the dropdown for picking filters; rather than clicking headers) Can't see an obvious solution to this.... hopefully there is one ?
8 Replies
LeandroFerreira
LeandroFerreiraβ€’5mo ago
πŸ€”
TextColumn::make('first_name')
->sortable()
->extraAttributes(['class' => 'hidden'])
->extraHeaderAttributes(['class' => 'hidden'])
TextColumn::make('first_name')
->sortable()
->extraAttributes(['class' => 'hidden'])
->extraHeaderAttributes(['class' => 'hidden'])
benlumley
benlumleyOPβ€’5mo ago
close.... that hides it; but it's still taking space up in the flex
LeandroFerreira
LeandroFerreiraβ€’5mo ago
yep, it is a workaround..
benlumley
benlumleyOPβ€’5mo ago
indeed
LeandroFerreira
LeandroFerreiraβ€’5mo ago
you could try to fix it creating a custom theme and customizing the css πŸ€”
benlumley
benlumleyOPβ€’5mo ago
yeah i'm checking with client whether separate columns is acceptable first πŸ™‚ thanks!
LeandroFerreira
LeandroFerreiraβ€’5mo ago
let me know if it works ✌️
benlumley
benlumleyOPβ€’5mo ago
will do ! found a solution.... i grouped the 2 columns into a stack, then used the 'hidden' class hack from above. in a stack; the hidden columns don't leave behind a gap; so think this is good

Did you find this page helpful?