Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method for sorting filament table that uses scout #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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