-
- Notifications
You must be signed in to change notification settings - Fork 855
Description
Currently, yajra/laravel-datatables doesn't provide native support for setting a minimum search length before triggering server-side queries. This leads to unnecessary database queries with 1-2 character searches, poor performance with large datasets, and suboptimal UX for autocomplete-style searches.
Current workarounds include backend approaches like if (strlen($searchValue) > 0 && strlen($searchValue) < 3) { return $builder->where('id', -1); } which still execute database queries, or frontend approaches using parameters with initComplete JavaScript which require manual injection.
I propose adding a minSearchLength() method to the HTML builder that would work like $this->builder()->minSearchLength(3)->serverSide() to prevent server requests until minimum length is reached, clear results when backspacing below minimum, and work seamlessly with existing DataTables configuration.
This would provide improved performance for large datasets, better UX for name/text searches, consistent behavior across implementations, and eliminate the need for custom JavaScript workarounds. This feature would be particularly valuable for customer/user search tables where 3+ character searches provide meaningful results while reducing server load.