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

KendoUI Datasource + External REST API (AJAX)

1 Answer 482 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 01 Mar 2013, 01:45 AM
Hello KendoUI Gurus - 

I am using a datasource and an external API (Parse.com) to grab data and populate it into a Pull-to-Refresh list view. All works well, however I am filtering the data using Kendo's "FILTER" (meaning I retrieve ALL records from the cloud first, and then apply a filter - which isn't going to work as the table grows, or at best horrible inefficient) I need to filter the data at the query level - the ajax code below works fine 

Question:
Is there anywhere I can put this line of code in the Kendo datasource configuration to have this line of code run in the AJAX request. 
  data: 'where={"username":"someUser"}',

Below is a link to some documentation on their site, I understand that it's an external service and that you may not support it, but I would like to double check with you and hopefully you can advise me on how to achieve what I need to do

Thanks in advance,

Regards

Darren

Ajax Working Code:

$.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/Messages",
  data: 'where={"username":"someUser"}',
  contentType: "application/json"
});


Kendo UI DataSource:

var listingdataSource = new kendo.data.DataSource({
                serverPaging: true,
                pageSize: 10,
                filter: { field: "messageTo", operator: "eq", value: localStorage.ls_userid},
                 sort: { field: "createdAt", dir: "desc" },
                transport: {
                  data: 'where={"username":"someUser"}',    
                read: {
                type: 'GET',
                headers: {'X-Parse-Application-Id':'xxx','X-Parse-REST-API-Key':'xxx'},
                url: "https://api.parse.com/1/classes/Messages",            
                 

                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
            
                }
            });
        

PARSE.COM REST API:
https://parse.com/docs/rest

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 04 Mar 2013, 06:46 AM
Hello Darren,

Yes, this should be possible. Basically the additional data option that you want to send to the server should be configured under the read object of the transport. Use the data field as you would do it if you were using the $.ajax's data. 
e.g.
transport: {
    read: {
        data: {
            id: 42,
            name: "John Doe"
        }
    }
}


Kind Regards,
Petur Subev
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
Darren
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or