Customize table default search debounce behavior

I am currently using a filament table search at one of the main pages of the website. If the users enters a letter, the search will be triggered immediately which creates some db load. How could I customize the default search to require a minimum of letters to be entered, search only when leaving the field or on enter, debounce timing and so on. I was able to do this with a custom form in a TextInput on getTableFilters with min() and lazy() but not with the default search field. Any recommendations how to do this?
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->limit(40)
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('name', 'like', "%{$search}%")
->orwhereRelation('names', 'name', 'like', "%{$search}%");
}),
];
}
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->limit(40)
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('name', 'like', "%{$search}%")
->orwhereRelation('names', 'name', 'like', "%{$search}%");
}),
];
}
5 Replies
Dennis Koch
Dennis Koch2y ago
I think all you can do is return a DB query that doesn't query any results (like 1 = 0) if the search is shorter than X letters.
Maxxx22
Maxxx22OP2y ago
Nice idea.. should have thought of it myself, Any Ideas about the lazy/debounce behavior too?
Dennis Koch
Dennis Koch2y ago
It's probably not supported.
Maxxx22
Maxxx22OP2y ago
Hmm, I could start customizing filament\vendor\filament\tables\resources\views\components\search-input.blade.php and so on creating a MR, would that be something that would work or even be appreciated?
Dennis Koch
Dennis Koch2y ago
I guess it would be useful, but I am not sure about a good syntax
Want results from more Discord servers?
Add your server