Force Autocomplete to refresh from data source every time

2 posts, 0 answers
  1. Peter
    Peter avatar
    1 posts
    Member since:
    Aug 2014

    Posted 15 Sep Link to this post

    I have an autocomplete on a page, and I would like the autocomplete to re-query the data source every time it is used.  For example, if someone loads up the page and they use the autocomplete control, everything is good.  But, if the underlying data in the database changes after the page is loaded, and after this initial query, any new rows are not reflected in the autocomplete control.  The control appears to hold on to the data that it got from the first query and not go back to the data source.

    If I refresh the page then it is ok, the new rows appear, but my users expect the autocomplete to always reflect that is in the database even if the data changes after the page is loaded and after the autocomplete control has queried the database already.

    Does anyone know how this can be achieved?  I have tried various combinations of ServerFiltering and specifying the Action Type as "Post" (as suggested by various internet articles), without getting the desired results.

    I believe my code is fairly normal, nothing unusual going on here I think (apart from the dodgy formatting):

    @(Html.Kendo().AutoComplete()
    .Name("newWorkOrderAutoComplete")
    .DataTextField("WorksOrderNumber")
    .MinLength(2)
    .HtmlAttributes(new { style = "width: 250px" })
    .DataSource(source =>
    {
    source.Read(read =>
    {
    read.Action("GetWorkOrderHeaders", "Kitting").Type(HttpVerbs.Post);
    })
    .ServerFiltering(false);
    })
    .IgnoreCase(true)
    .Suggest(true)
    .Animation(a =>
    {
    a.Open(open =>
    {
    open.Duration(300);
    open.Zoom(ZoomDirection.In);
    });
    a.Close(close =>
    {
    close.Duration(300);
    close.Zoom(ZoomDirection.Out);
    });
    })
    )

     

    Thanks in advance,

    Peter

  2. Nencho
    Admin
    Nencho avatar
    1646 posts

    Posted 19 Sep Link to this post

    Hello Peter,

    The aimed functionality could be achieved by enabling the server filtering. In other words, if you set it to true, the AutoComplete will hit the method in the controller, each time a character is typed/deleted. Hence, you can assure that you can query the current state of your Data Base. 

    Another option would be to manually trigger the read method on the data source:

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-read

    This usage will trigger the call to the method, specified in the declaration of the AutoComplete. You can use, for example, the open event of the AutoComplete. Hence, each time the autocomplete is opened, you can manually call this.dataSource.read() and the method responsible for population will data will be hit:

    Open event of AutoComplete: http://docs.telerik.com/kendo-ui/api/javascript/ui/autocomplete#events-open

    Hope this information would help to achieve your scenario.

    Regards,
    Nencho
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top