KendoUI Datasource + External REST API (AJAX)

2 posts, 0 answers
  1. Darren
    Darren avatar
    9 posts
    Member since:
    Feb 2013

    Posted 28 Feb 2013 Link to this post

    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
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 04 Mar 2013 Link to this post

    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!
Back to Top