Force enter to override searchDelay and search immediately?

Force enter to override searchDelay and search immediately?

sapotsapot Posts: 14Questions: 8Answers: 0

I have searchDelay set to 1000 and now I want to force the search if the user presses Enter.

I know about search.return but that is not what I want, I want that to be false. I want to still do searches on all keyup, managed by searchDelay but just have a kind of override where if we press enter it immediately searches.

How can I do that?

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    There is no option for that in DataTables I'm afraid. If that it something you need, you could bind your own key event listener to the input and when enter is pressed call search() with the value in the input element. That is safe to do, because when DataTables' own delay timer completes, it would see that the search value has already been applied and thus not apptempt to apply it again.

    Allan

  • sapotsapot Posts: 14Questions: 8Answers: 0

    thank you very much, that's exactly it. I thought about that solution but was afraid it would run twice the search when the delay ends. I'll try it out.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    There is a check in the code to see if the new search term matches the old. If so, it doesn't bother running it.

    Allan

Sign In or Register to comment.