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

add debounce filter docs #605

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 6.x/crud-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,23 @@ CRUD::filter('trashed')
<a name="tips-and-tricks"></a>
## Tips and Tricks

<a name="debouncing-filters"></a>
### 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.

<a name="adding-a-filter-using-array-syntax"></a>
### Adding a filter using array syntax

Expand Down