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

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

1 Answer 554 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
marko
Top achievements
Rank 1
marko asked on 24 Feb 2014, 06:54 PM
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.

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 25 Feb 2014, 09:45 AM
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!
Tags
Data Source
Asked by
marko
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or