Search code examples
kendo-uikendo-asp.net-mvckendo-datasourcekendo-autocomplete

Kendo datasource change read url on request start


I am currently doing this to change the read url dynamically on my kendo datasource. The datasource is used for a kendoautocomplete text box and for each key typed the list of suggestions are fetched through a get request.

  requestStart: function (e) {
                    var text = $('#txtMail').val();
                        e.sender.transport.options.read.url = "/Feed/AutoCompleteUser?text=" + text + "&limit=10";
                    }

This works fine the first time , but consequent request's are exactly same as the first request it never hits this piece of code. What am i missing?

Please advice.


Solution

  • You can just add a data parameter for your read request, like so, in this case, as the request is sent as a get, it will append the query with the fields inside your data object.

    By adding the function like this, it will get called every time you make a request.

    function getRequestParameters() {
        return {
            text: $('#txtMail').val(),
            limit: 10
        };
    }
    
    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "http://demos.telerik.com/kendo-ui/service/products",
                data: getRequestParameters,
                dataType: "jsonp"
            }
        }
    });
    

    You can find more about configuring the datasource operations here: