Delay in server side search query

Delay in server side search query

jokohewsjokohews Posts: 7Questions: 2Answers: 0

Is it possible to wait for the user to stop typing in the search bar before sending the query to the server side api?

It seems to hit the server every key stroke. Any way to add a second or 2 delay before posting?

Thanks,

Jay

Answers

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

    The searchDelay option is the builtin way to delay the searches. If this isn't what you want there are some threads on this forum that discuss other techniques to delay the server side search request, such as using your one input that uses a change event instead of keyup or I think there is a debounce solution someone posted. Take a look for those if interested.

    Kevin

  • jokohewsjokohews Posts: 7Questions: 2Answers: 0

    Thanks for the quick reply.

    The searchDelay option looks right... it doesn't seem to have any effect. I set it to 10s to exagerate the delay and the search fires immediately.. it sends a new api post for every character. I've added like this..

            var apiTable = $('#datatable_tabletools_api').DataTable({
                "processing": true,
                "serverSide": true,
                "bStateSave": true,
                "ajax": $.fn.dataTable.pipeline({
                    url: apiSearch,
                    pages: 5 // number of pages to cache
                }),
                "searchDelay": 10000,
                "lengthMenu": [10, 25, 50, 75, 100, 250, 500],
                "iDisplayLength": 15,
                "order": [[9, "desc"]],
    

    Any thoughts?

  • jokohewsjokohews Posts: 7Questions: 2Answers: 0

    it looks like it's taking effect.. thanks

  • jokohewsjokohews Posts: 7Questions: 2Answers: 0

    It's difficult to tell.. is the delay sliding? if a key stroke happens before the delay time, does it extend the delay?

This discussion has been closed.