Question

I'm becoming crazy with Kendo UI AutoComplete component. I'm using my own functions to access data with jQuery, so I have to set the AutoComplete dataSource.transport.read as a function. The code is something like this.

minLengthAtocomplete = 3;

$('#autocomplete').kendoAutoComplete({
    minLength : 3,
    filter : "contains",
    dataValueField : "key",
    dataTextField : "value",
    dataSource : new kendo.data.DataSource({
        transport : {
            read : _OnTransportRead
        },
        schema : {
            /* object schema */
        }
    })
});

function _OnTransportRead(e) {
    var text = $.trim(e.data.filter.filters[0].value);

    if (text && text.length >= minLengthAtocomplete) {
        _GetUsers(
            text,
            function onSuccess(data) {
                var users = [];
                 /* sets users with info in data */
                e.success(users);
            },
            function onError(error) {
                /* stuff with error */
            }
        );
    }
}

function _GetUsers(userName, onSuccess, onError) {
    /* Ajax to get users from DB */
}

This code runs perfectly, but dataSource.transport.read is called only the once. I do a first search with the text 'michae' and AutoComplete component runs its dataSource.transport.read as expected. Then, I add a one more letter to search for 'michael', and dataSource.transport.read is never called again. Is so frustrating!

I tried using autoSync dataSource property, manual dataSource Sync, set new dataSource objects on AutoComplete dataBound, but no luck.

What am I doing wrong? What am I forgetting?

Thanks in advance.

Was it helpful?

Solution

You should enable serverFiltering in order for the data source to make requests every time.

$('#autocomplete').kendoAutoComplete({
    minLength : 3,
    filter : "contains",
    dataValueField : "key",
    dataTextField : "value",
    dataSource : new kendo.data.DataSource({,
        serverFiltering: true, 
        transport : {
            read : _OnTransportRead
        },
        schema : {
            /* object schema */
        }
    })
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top