2

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.

AnoojNair
  • 491
  • 3
  • 11
  • 18

1 Answers1

3

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:

Icepickle
  • 12,689
  • 3
  • 34
  • 48
  • what if my URL needs to change per request.. for example this OData V4 url looks like this: `https://localhost:64810/odata/SearchOrders(orderid=334424)` so there's really no query string involved, which is what the `data` was designed for – bkwdesign Mar 14 '18 at 16:36
  • @bkwdesign I believe there was a transformation available, or you could use string literals to enter your query – Icepickle Mar 14 '18 at 17:46
  • 1
    It doesn't work for me. `data` does not seem to do anything. – nowox Jan 03 '19 at 11:51
  • 1
    @nowox I just tested it on the demo site where I am linking to and I can add additional parameters in the request object, so not doing anything is not really helpful for me (neither do I know what you would like to achieve). Do you have a question available somewhere? – Icepickle Jan 03 '19 at 12:01
  • 1
    You're right I missed the correct format. I was using `{ read: "url", data: {foo: true}}` instead of `{ read: { url: "url", data: {foo: true}}}`. Sorry about this. – nowox Jan 03 '19 at 12:05