Kendo UI - DataSource works when using fetch(), but not read()

2 posts, 0 answers
  1. marko
    marko avatar
    20 posts
    Member since:
    Oct 2006

    Posted 24 Feb 2014 Link to this post

    I have a Kendo UI DataSource that works when I use fetch(), but when I use the exact same configurtation with read() it fails. This is a problem as I need to retrieve data more than once and I can't do that with fetch().

    Here is the DataSource code - 

    var FieldsDataSource = new kendo.data.DataSource({
    transport: {
    read: {
    url: "../WebServiceAddress",
    dataType: "json",
    type: "POST",
    contentType: 'application/json; charset=utf-8',
    cache: false
    },
    parameterMap: function() {
    return "{some mapping that has been confirmed to work}";
    },
    schema: {
    data: function (data) {
    if (data && data.d) {
    //execution gets to here and stops
    return data.d;
    }
    else {
    return [];
    }
    },
    }
     
    });


    Here is the code that calls the DataSource.read() function - function loadFields() {

    FieldsDataSource.read(function() {
    var data = this.data();
    if (data.length > 0) {
     
    for (var i = 0; i < data.length; i++) {
    var dataitem = data[i].Key;
    $("#" + dataitem + "_field").prop("checked", data[i].Value);
    }
    }
    });
    }


    If I change "FieldsDataSource.read(function()" to "FieldsDataSource.fetch(function()" everything works, but that doesn't make sense as I was under the impressionthat read and fetch do the same thing the difference being fetch only gets data once.

    What I do know is that the data is being returned from the server, I can see it in fiddler - but the execution stops in the schema section where I flagged it in my code sample.

    Apologies if I am asking a really obvious question, but I'm very new to Kendo.
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 25 Feb 2014 Link to this post

    Hello marko,

    As you may know unlike fetch, the read method does not accept a callback as an argument. Thus, you will need to use the change event to iterate over the data.

    Regards,
    Rosen
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
Back to Top