FilamentF
Filament2y 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'),


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
Video uploaded to CleanShot Cloud
Solution
Figured out. I had the Eloquent Query using the latest() method and removing that fixed it,
Was this page helpful?