How do I get searchDelay to apply to a string replace on .dataTables_filter input?

How do I get searchDelay to apply to a string replace on .dataTables_filter input?

hm123hm123 Posts: 84Questions: 27Answers: 1

Test case: http://live.datatables.net/nefewovi/1/edit

Here you can see that writing "tiger" in the search box, replaces that search term with the word "sonya" instead, bringing up the results of sonya immediately. This happening immediately is one problem.

Yet with searchDelay applied, the results go back to "tiger" after 3 seconds. Which is another problem.

Now while this table is small, a huge dataset would lag if search ran immediately on every keypress. Therefore I would expect searchDelay to throttle the filter. How do I get that to work here?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,345Questions: 26Answers: 4,954
    edited July 2022 Answer ✓

    This happening immediately is one problem.

    Due to calling search() in your keyup event. This is outside the search Datatables is using for the search input. searchDelay doesn't affect searching via the APIs.

    Yet with searchDelay applied, the results go back to "tiger" after 3 seconds. Which is another problem.

    Change the input value to sonya.

    Something like this:
    http://live.datatables.net/nefewovi/2/edit

    If using searchDelay doesn't behave the way you like you might need to create a debounce function. See this thread for some ideas.

    Kevin

Sign In or Register to comment.