F
Filament5mo ago
QCTFW

Disable Default Sort while Searching with Scout

I use Laravel Scout with Meilisearch for table search. I want to sort the table based on Meilisearch's rank but defaultSort() overrides the Meilisearch's rank. How to disable the defaultSort() while on search?
$table
->selectCurrentPageOnly()
->defaultSort('name', 'asc')
->searchDebounce('500ms')
->columns([...])
->filters([...])
->actions([...]);
$table
->selectCurrentPageOnly()
->defaultSort('name', 'asc')
->searchDebounce('500ms')
->columns([...])
->filters([...])
->actions([...]);
protected function applySearchToTableQuery(Builder $query): Builder
{
$this->applyColumnSearchesToTableQuery($query);

if (filled($search = $this->getTableSearch())) {
$meiliBuilder = Book::search($search);

$query->whereIn('id', $meiliBuilder->keys());

// Already tried this but still not working
$this->tableSortColumn = null;
$this->tableSortDirection = null;
}

return $query;
}
protected function applySearchToTableQuery(Builder $query): Builder
{
$this->applyColumnSearchesToTableQuery($query);

if (filled($search = $this->getTableSearch())) {
$meiliBuilder = Book::search($search);

$query->whereIn('id', $meiliBuilder->keys());

// Already tried this but still not working
$this->tableSortColumn = null;
$this->tableSortDirection = null;
}

return $query;
}
2 Replies
QCTFW
QCTFWOP5mo ago
up still not find the answer
Sandro Gehri
Sandro Gehri5mo ago
We have the same issue. I just created a PR to disable sorting with a closure when a table search is active: https://github.com/filamentphp/filament/pull/13540
GitHub
Add option to pass a closure as the sortable condition by gehrisand...
Description This PR adds the ability to pass a closure as the sortable condition: TextColumn::make('date') ->sortable(fn() => $this->hasTableSearch()), Functional changes Cod...
Want results from more Discord servers?
Add your server