Is there a way to incorporate debounce time into a dynamic search box that filters data in a table? I have explored some solutions online, but my code varies slightly as I do not use throttle or similar functions.
This is my template code:
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Search element">
And the TypeScript for it is:
applyFilter(filterValue: string) {
this.tableDataSource.filter = filterValue.trim().toLowerCase();
}
I would like to implement a debounce time so that the search only occurs every 2 seconds, preventing multiple requests with every change.
Thank you in advance.
I attempted to invoke the method from another method using a pipe:
filterData(filterValue: string) {
this.applyFilter(filterValue).pipe(debounceTime(2000))
}
However, it now displays an error stating pipe does not exist on type void.