Sorting a table component (not a resource) not working

Hello, I have a component which displays a table. The query is just the all() method on the relevant model.

I have some custom filters with select fields, that all work to update the query and therefore the table results.

I want the sort to be selectable, so I made a select field , with the option to sort a given column asc or desc.

The records will not update however:

    public function getTableQuery() {
        return FeaturedProduct::query();
    }

    protected function getTableFilters(): array
    {
        return [
            Tables\Filters\Filter::make('filter_sort')
                ->form([
                    Select::make('sort')
                        ->label(__('configurator.teaser.sort'))
                        ->reactive()
                        ->default(3)
                        ->helperText(__('featured.filter.sort.helptext'))
                        ->options([
                            1 => __('featured.sort.price_asc'),
                            2 => __('featured.sort.price_desc'),
                            3 => __('featured.sort.default')
                        ]),
                ])
                ->query(function (Builder $query, $data, $livewire) {
                    $sort = $data['sort'] ?? NULL;
                    switch ($sort) {
                        case 1:
                            return $query->orderBy('price_total');
                            break;
                        case 2:
                            return $query->orderByDesc('price_total');
                            break;
                        case 3:
                            return $query->orderByDesc('weight');
                            break;
                    }
                    return $query;
                }),
        ];
    }


This filter works the same way as the other, working filters, but it seems that ordering is restricted, because all the 'where's work, just the 'order's do not. What am I missing here?

Thanks
Was this page helpful?