From f2638926f45853e77103b339d38ed9309ce6c137 Mon Sep 17 00:00:00 2001 From: pxpm Date: Fri, 4 Oct 2024 11:08:29 +0100 Subject: [PATCH] add debounce filter docs --- 6.x/crud-filters.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/6.x/crud-filters.md b/6.x/crud-filters.md index 6c5d370b..205e3154 100644 --- a/6.x/crud-filters.md +++ b/6.x/crud-filters.md @@ -621,6 +621,23 @@ CRUD::filter('trashed') ## Tips and Tricks + +### Add a debounce time to filters + +Filters can be debounced, so that the filtering logic is only applied after the user has stopped typing for a certain amount of time. This is useful when the filtering logic is expensive and you don't want it to run on every keystroke. To debounce a filter, you can use the following code: + +```php + +CRUD::filter('name') + ->type('text') + ->debounce(1000) // debounce time in milliseconds + ->whenActive(function($value) { + // CRUD::addClause('where', 'name', 'LIKE', "%$value%"); + }); +``` + +All filter types accept a `debounce`, like for example the simple filter, range filter etc. + ### Adding a filter using array syntax