This is a migrated thread and some comments may be shown as answers.

Force Autocomplete to refresh from data source every time

1 Answer 1509 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 15 Sep 2017, 09:03 AM

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

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 19 Sep 2017, 07:22 AM
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.
Tags
AutoComplete
Asked by
Peter
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or