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

Why my kendo ui autocomplete only works at the first time after refresh browser?

2 Answers 105 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Jingyu
Top achievements
Rank 1
Jingyu asked on 18 Dec 2014, 06:24 PM
Hi,

Would you please help me to find what reason cause my code only works at the first time after refresh browser?

Thank you very much!
J

The following is my code:-----------------------------------------------
<div >
    <input id="txtName"  data-role="autocomplete"    data-filter="startswith"   data-min-length="1" data-placeholder="Select a Name"  data-text-field="FullName"
           data-bind="value:inputsearchName, source: searchedName, enabled: isEnabled, events: { select: selectPerson, change: onChange}" />
    Name :<span data-bind="text: selectedPerson.LogonName"></span>
</div>
<script>
    var viewModel = kendo.observable({
        searchedName: new kendo.data.DataSource({
            transport: {
                read: {
                    cache: false,
                    url: "@Url.Action("GetNames")",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    type: "Get",
                }
                , parameterMap: function (options, operation) {
                    if (operation === "read") {
                        return {
                            startsWith: $("#txtName").data("kendoAutoComplete").value()
                        };
                    }
                }
            },
        }),
        selectedPerson: {},
        suggest: true,
        selectPerson: function (e) {
            var item = e.sender.dataItem(e.item.index());
            viewModel.set("selectedPerson", item);
        }
    });
    kendo.bind($(document.body), viewModel);
</script> 
C#-MVC Controller Code:----------------
public JsonResult GetNames(string startsWith)
        {
            List<AutoCompletionGroup> employeeList;
            employeeList = Employee.GetEmployeesByCriteria(startsWith);
            return Json(employeeList, JsonRequestBehavior.AllowGet);
        }


2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 22 Dec 2014, 08:41 AM
Hi Jingyu,

I am afraid that the provided information is not sufficient enough in order to determine what exactly goes wrong.
Could you please provide a small but runnable test page which isolates the issue? Could you please specify what exactly you mean by "does not work" - do you have problems with the rendering, styling, binding or maybe anything else is not working?

Looking forward to your reply.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Dave
Top achievements
Rank 1
answered on 29 Jun 2015, 10:44 PM
This tripped me up also and since there is no answer given, my issue was I did not set serverFiltering to true.


$('#autocomplete').kendoAutoComplete({
    minLength : 3,
    filter : "contains",
    dataValueField : "key",
    dataTextField : "value",
    dataSource : new kendo.data.DataSource({,
serverFiltering: true,
        transport : {
            read : /* ...... */
        },
        schema : {
            /* object schema */
        }
    })
});
Tags
AutoComplete
Asked by
Jingyu
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Dave
Top achievements
Rank 1
Share this question
or