There is a code for ui-autocomplete, defined in $(function() {} :

  $("#accountValue").autocomplete({ minLength: 0, source: function(request, response) { $.ajax({ url: '@Url.Action("GetAccountNumbers", "Diary")', type: "get", dataType: "json", data: { filter: request.term }, success: function(data) { response(data); } }); } }).focus(function() { $(this).autocomplete("search", ""); }); $(".ui-autocomplete").css({ "max-height": "300px", "max-width": "260px", "box-sizing": "border-box", "-ms-box-sizing": "content-box", "-moz-box-sizing": "border-box", "-webkit-box-sizing": "border-box", "overflow": "auto" }); 

Handler Method:

  [HttpGet] public JsonResult GetAccountNumbers(string filter) { var result = new List<string>(); try { var sessionHelper = new SessionHelper(this.HttpContext); result = sessionHelper.AccountNumbers.Where(item => !string.IsNullOrEmpty(item) && item.ToLower().StartsWith(filter.ToLower())).ToList(); } catch (Exception exception) { } return Json(result, JsonRequestBehavior.AllowGet); } 

The handler method returns a large number of records (about 24 thousand), which greatly slows down the script. How can I increase the speed? Maybe dynamic data loading? Or from the server to give parts? Tell me, please, how to do this?

Update!
On the server, the data gets quickly. Brakes, because there are many calls to the handler method. (thanks to @teo van kot for the tip). The question is how not to pull the method so often.

    1 answer 1

    Why do you need to return a large number of records in the autocompiler? After all, it is obvious that the screen still does not fit more than 30.

    On the server, simply limit the number of records returned from the database. Or, if you still need a different number of records in different cases, pass this parameter to the method:

     url: '@Url.Action("GetAccountNumbers", "Diary", new { RowNumber = 30 })', 
    • If the screen does not fit the record - appears scrolled. A large number of entries - in case the user does not enter any text, but simply scrolls. It turns out just a drop-down list with all possible values. - Daria
    • @Daria your list is redrawn each time you press a key. That is, for each press - the request to the server goes. If you are already pulling the list all at once - do everything on the client, without contacting the server, the autocompiler has such an opportunity - teo van kot
    • @ teo van kot "your list is redrawn every time you press a key." - as an option, it would be possible to take only, for example, 50 records on the server and return them to the client. But how to specify which record to take (so as not to take the same area all the time)? And what can be done on the client to speed up the download, tell me, please. - Daria
    • @Daria to understand how to speed up the client, you need to see if the client is lagging at all. See what happens when loading in the browser (there are special utilities in chrome and firefox). And if not - you should already look at the server code, which you do not have in the question - teo van kot