Hiren Kagrana
Hiren Kagrana

Reputation: 932

Kendo UI MVC Autocomplete server filtering after user stop typing

I am using Kendo UI autocomplete in my asp.net mvc application, Kendo autocomplete callbacks the server method on each key strock which over heads the server requests. Is there any way to manually callback the server using autocomplete to get the data source.

My code is as below

 @(Html.Kendo().AutoComplete()
 .Name("patientSearch")
 .DataTextField("patientSearch")
 .MinLength(2)
 .Placeholder("Search by Lastname, Firstname or DOB")
 .HtmlAttributes(new { id = "textPatientSearch" })
 .Template("<B>${data.LastName}, ${data.FirstName} </B> - ${ kendo.toString(kendo.parseDate(data.DateOfBirth),'MM/dd/yyyy') } ")
 .DataSource(source =>
 {
    source.Read(read =>
    {
        read.Action("GetFilteredPatient", "Order").Data("onAdditionalData");
    })
    .ServerFiltering(true);
 }))

I have found the jquery solution for check that user stops typing, the code is as below:

$(function(){
        //setup before functions
        var typingTimer;                //timer identifier
        var doneTypingInterval = 2000;  //time in 3 ms

        //on keyup, start the countdown
        $('#textPatientSearch').keyup(function(e){
            clearTimeout(typingTimer);
            typingTimer = setTimeout(doneTyping, doneTypingInterval);
        });

        //on keydown, clear the countdown
        $('#textPatientSearch').keydown(function(){
            clearTimeout(typingTimer);
        });

        //user is "finished typing," do something
        function doneTyping () {
           **//WHAT TO DO HERE**
        }
    });

I don't know how to manually server filter the autocomplete on doneTyping function, Please help.

Upvotes: 3

Views: 4337

Answers (1)

Hiren Kagrana
Hiren Kagrana

Reputation: 932

Finally, I have found the solution, The Kendo UI provides the Delay (default: 200) method which accepts the integral value in milliseconds, which waits for the next user strock from last keystrokes in specified milliseconds, if the user fails to send the keystroke in specified delay time, the kendo autocomplete fires the server filtering automatically.

Upvotes: 7

Related Questions