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

Parsing of the transport:read results

5 Answers 1112 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 27 May 2014, 03:24 PM
Hello,

I currently have the problem that I use the standard read method to get information from the REST endpoint of a Crm 2013 Server. The results have a format like:

data:{
  d:{
    results:[{Name: "Test1"},{Name: "Test2"},{Name: "Test3"},...]
  }
}

This leads to huge problems in the DataSource.fn.success function because only an array is expected there and within the function that._pristineData = data.slice(0); fails with "Uncaught TypeError: undefined is not a function.

Is there now any way to provide different data on success of the read in a dataSource?

5 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 28 May 2014, 06:08 AM
Hello Thomas,

You can instruct the DataSource from which field in the original response the data should be read. This is possible by specifying schema.data field in DataSource configuration. For the response bellow it should be set as follows:
{
 schema: {
  data: "data.d.results"
 }
}


Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Thomas
Top achievements
Rank 1
answered on 28 May 2014, 07:17 AM
Hello Nikolay,

The problem is, I do not reach the schema since the operation fails already in the success of the read otherwise I could then use

{
  schema: {
    parse: function(data){
      return data.d.results;
    }
  }
}
But the operation abort on the said try to slice an object instead of an array:

that._pristineData = data.slice(0);  XUncaught TypeError: undefined is not a function.
kendo.all.js:7464






0
Nikolay Rusev
Telerik team
answered on 29 May 2014, 06:24 AM
Hello Thomas,

Here is an example of the DataSource in order to extract the data array from correct field in the response.
http://trykendoui.telerik.com/@rusev/AVEk

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
CS
Top achievements
Rank 2
answered on 30 May 2014, 05:17 AM
Hello Nikolay,

If I use the default read with just the URL it doesn't seem to work that way, and also properties like "success:" or "complete:" seem to be ignored.
The core problem was that I needed also filtering, and I thought with "serverFiltering: true" I needed the default read method because the paramMap gets ignored and hence I lose the filter options, but then I saw that the filter options get also passed to the read so I can use them there already with a custom read.
0
Nikolay Rusev
Telerik team
answered on 02 Jun 2014, 09:34 AM
Hello Stefan,

`If I use the default read with just the URL it doesn't seem to work that way, and also properties like "success:" or "complete:" seem to be ignored.` - the example that I've created for you is one-to-one simulation on how the DataSource works with the type of response you've posted in the first forum post, assuming that the response contains well formed JSON object.

The following section of the example is the server request-JSON response mock-up:
transport: {
 read: function(options) {
  options.success(response);
 }
},


The following projects shows various server implementations: 
 - binding to web service
 - binding in asp.net mvc

`The core problem was that I needed also filtering, and I thought with "serverFiltering: true" I needed the default read method because the paramMap gets ignored and hence I lose the filter options, but then I saw that the filter options get also passed to the read so I can use them there already with a custom read.` - all current state of the DataSource will be send to the read method - filter descriptors, sort descriptors etc. if server operation is enabled, i.e serverFiltering: true, serverSorting: true etc.

Regards,
Nikolay Rusev
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
Thomas
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Thomas
Top achievements
Rank 1
CS
Top achievements
Rank 2
Share this question
or