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

Kendo DataSource (AJAX) "GET" / Custom Query

2 Answers 768 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Damien
Top achievements
Rank 1
Damien asked on 04 Feb 2013, 04:37 AM
Below is a data source which connects to an external REST service. All is well, except when I want to do a query and not return the entire set of data. I need to URL encode with messageTo = xxx but I am unsure of the correct syntax in a Kendo datasource or if this is supported at all..

Are you able to assist? Source code below. The code in BOLD is not working

Best Regards,

Damien.


var dataSource = new kendo.data.DataSource({
            serverPaging: true,
            pageSize: 10,
            transport: {
                read: {
            type: 'GET',
            headers: {'X-Parse-Application-Id':'MY_AUTH_KEY','X-Parse-REST-API-Key':'MY_SECOND_KEY'},
            url: "  https://api.parse.com/1/classes/Messages",
            data: "{ messageTo: 'USER_ID_HERE'}",
 
            dataType: "json" // JSONP (JSON with padding) is required for cross-domain AJAX
                },
             
            },
            schema: { // describe the result format
                data: "results" // the data which the data source will be bound to is in the "results" field
            }
        });

2 Answers, 1 is accepted

Sort by
0
Damien
Top achievements
Rank 1
answered on 04 Feb 2013, 12:05 PM
Here is the code Parse.com has recommended for the REST API


I have tried everything and cannot get this to work!!!! 
All I want to do is specify additional query options instead of returning everything!!!!!

$.ajax({
  type: 'GET',
  headers: {'X-Parse-Application-Id':'PARSE-APP-ID','X-Parse-REST-API-Key':'PARSE-REST-KEY'},
  url: "https://api.parse.com/1/users",
  data: 'where={"username":"someUser"}',
  contentType: "application/json"
});
0
Daniel
Telerik team
answered on 06 Feb 2013, 06:41 AM
Hello Damien,

The dataSource transport operations are just a wrapper for the jQuery ajax method so generally you should be able to use the same approach. If the parameters should be send in JSON format then you should rather use the transport parameterMap function to add them to the request e.g.

transport: {
    read: {
        type: 'GET',
        headers: { 'X-Parse-Application-Id': 'MY_AUTH_KEY', 'X-Parse-REST-API-Key': 'MY_SECOND_KEY' },
        url: "https://api.parse.com/1/classes/Messages",               
        dataType: "json" // JSONP (JSON with padding) is required for cross-domain AJAX
    },
    parameterMap: function (data, operation) {
        return kendo.stringify({ messageTo: "USER_ID_HERE" });
    }
}
Regards,
Daniel
the Telerik team
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
Damien
Top achievements
Rank 1
Answers by
Damien
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or