Skip to content

Method for sorting filament table that uses scout#8

Open
bensondevs wants to merge 1 commit intokainiklas:mainfrom
bensondevs:patch-1
Open

Method for sorting filament table that uses scout#8
bensondevs wants to merge 1 commit intokainiklas:mainfrom
bensondevs:patch-1

Conversation

@bensondevs
Copy link

@bensondevs bensondevs commented Mar 28, 2024

Problem

When using filament table sortable() it is forced that we need to use the Eloquent Builder and we cannot use the Scout Builder as the query parameter. This causes the sorting is always using the model's database table column based sorting, meanwhile sometimes we have custom table column value that's only being stored in the index table (Meilisearch, Algolia, etc)

Solution

The created method of scoutQuerySorting will resolve the issue and make the sorting using the custom column that only exists in the index table column.

Example of Usage

TextColumn::make('custom_calculation_column')
                ->state(fn (Model $model) => $event->getSomeCalculationFromIndex())
                ->sortable(query: fn (
                    Builder $query,
                    string $direction,
                ): Builder => $this->scoutQuerySorting(
                    'custom_calculation_column',
                    $query,
                    $direction,
                ))
                ->toggleable(),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant