F
Filament11mo ago
Abi

Can't get `sortable()` method on the Table Builder to work

I have the following code to sort the table and I can't seem to get it to work.
Tables\Columns\TextColumn::make('user.name')
->url(fn($record) => CustomerResource::getUrl('view', [$record]))
->getStateUsing(fn($record) => Str::title($record->user->name))
->openUrlInNewTab()
->alignCenter()
->searchable()
->sortable()
->label('Parent Name'),
Tables\Columns\TextColumn::make('user.familyMembers.name')
->getStateUsing(fn($record) => $record->user->familyMembers->map(fn($member) => Str::title($member->name))->unique()->join('<br>'))
->html()
->alignCenter()
->searchable()
->sortable()
->label('Possible Kids Name'),
Tables\Columns\TextColumn::make('next_invoice_date')
->label('Next Invoice Date')
->alignCenter()
->sortable()
->date(),
Tables\Columns\TextColumn::make('created_at')
->date()
->alignCenter()
->label('Subscribed On'),
Tables\Columns\IconColumn::make('invoice_url')
->icon('fas-file-invoice-dollar')
->alignCenter()
->color('warning')
->url(fn($record) => $record->invoice_url)
->openUrlInNewTab()
->label('Invoice'),
Tables\Columns\TextColumn::make('user.name')
->url(fn($record) => CustomerResource::getUrl('view', [$record]))
->getStateUsing(fn($record) => Str::title($record->user->name))
->openUrlInNewTab()
->alignCenter()
->searchable()
->sortable()
->label('Parent Name'),
Tables\Columns\TextColumn::make('user.familyMembers.name')
->getStateUsing(fn($record) => $record->user->familyMembers->map(fn($member) => Str::title($member->name))->unique()->join('<br>'))
->html()
->alignCenter()
->searchable()
->sortable()
->label('Possible Kids Name'),
Tables\Columns\TextColumn::make('next_invoice_date')
->label('Next Invoice Date')
->alignCenter()
->sortable()
->date(),
Tables\Columns\TextColumn::make('created_at')
->date()
->alignCenter()
->label('Subscribed On'),
Tables\Columns\IconColumn::make('invoice_url')
->icon('fas-file-invoice-dollar')
->alignCenter()
->color('warning')
->url(fn($record) => $record->invoice_url)
->openUrlInNewTab()
->label('Invoice'),
I have tried to use ->defaultSort('next_invoice_date'); on the table, but I can't get the sortable to work. Here is what is happening https://share.cleanshot.com/kfv42nWM
CleanShot Cloud
CleanShot 2024-01-12 at 20.00.03
Video uploaded to CleanShot Cloud
Solution:
Figured out. I had the Eloquent Query using the latest() method and removing that fixed it,
Jump to solution
2 Replies
Abi
AbiOP11mo ago
The sortable() method is on multiple columns and there is also a default filter set on the table. even disabling the other sortable on the other columns don't help is this is a problem if one of the column uses a relation? any advice on this please
Solution
Abi
Abi11mo ago
Figured out. I had the Eloquent Query using the latest() method and removing that fixed it,
Want results from more Discord servers?
Add your server