Start search not on every key-press

Start search not on every key-press

markzzzmarkzzz Posts: 49Questions: 8Answers: 1
edited March 2023 in Free community support

Hi,

I'm using server side processing (ajax) on my DataTables.
I've configured the #grid_filter input search.

I've noticed that on every digit, it triggers the preXhr.dt event and so the ajax request to the server.
This is of course "annoying" when I type a word such like "Mario" (i.e. 5 request on every letter).

Can I trigger it after X seconds of the last key digit? More natural as process...

What's the correct way?
Tried this: https://datatables.net/reference/option/searchDelay

But its act weird, such as "first digit", start, than wait, than seems "random"...

Replies

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    You can try one of the debounce solutions found on the forum. Maybe this thread will help.

    Kevin

  • markzzzmarkzzz Posts: 49Questions: 8Answers: 1

    Just wow!! Looks like a charm! Only a thing to be improved mayb: ctrl+a (i.e. select all) shouldn't retrigger the ajax server, how would you take care of this?

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    I would look at checking for which key is pressed and not search if ctrl+a is pressed. This SO thread shows how to check which key is pressed.

    Kevin

Sign In or Register to comment.