Data not displaying in ListView when working with OData v3

5 posts, 0 answers
  1. Abhishek
    Abhishek avatar
    7 posts
    Member since:
    Jul 2012

    Posted 17 May 2012 Link to this post

    Hi 

    I am starting with Kendo UI. I have an exisiting OData Service at http://enservice.indiamvp.net/EventNetworkingService.svc/Cities that is based on Odata v3. 

    I am trying to display the cityname in a Mobile ListView. I have set up my datasource as follows:
    var speakerData = new kendo.data.DataSource(
                    {
                        type: "odata",
                        transport: {
                            read: {
                                // the remote service url
                                url: "http://enservice.indiamvp.net/EventNetworkingService.svc/Cities",
                                dataType: "jsonp",
                                data: {
                                    Accept: "application/json"
                                }
                            }
                        },
                        serverfiltering: false,
                        serverPaging: true,
                        pageSize: 10,
                        batch: false,
                        schema: {
                        data: "d",
                            model: {
                                id: "CityID",
                                fields: {
                                    CityID: { type: "number" },
                                    CityName: { type: "string" }
                                }
                            }


                        }
                    }
                    );

    To initialise the ListView I am using the following:

                    $("#speakersView").kendoMobileListView(
                    {
                        template: "<strong>${speakerData.CityName}</strong><br/>",
                        dataSource: speakerData.read()
                    }
                    );

    Both the functions are in <head> element and not in the $document.ready function. I am using data-init on the view. Checking from Chrome Dev Tools, I can see that the JSON data is downloaded. 
    However, nothing gets displayed on the ListView. Stepping through the JS i see that there is a exception getting generated: "speakerData is not defined" pointing to the fact the maybe the DataSource is not initialised properly.

    Can someone recommend on what I could be doing incorrectly?

    Thanks
    Abhishek
  2. Petyo
    Admin
    Petyo avatar
    2438 posts

    Posted 18 May 2012 Link to this post

    Hi,

    Can you please try using 

    $("#speakersView").kendoMobileListView({
              template: "<strong>${speakerData.CityName}</strong><br/>",
              dataSource: speakerData
          });

    Kind regards,
    Petyo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Abhishek
    Abhishek avatar
    7 posts
    Member since:
    Jul 2012

    Posted 18 May 2012 Link to this post

    Thanks for sending detailed instructions about the setting the error correct. As it happened, it was a case of misconfiguration. I took the following steps to set the DataSource correctly:
    1. Set dataSource : speakerData // no .read()
    2. ListView template: "${CityName}" // no prefix here.
    3. Remove the schema (including data) from the DataSource definition

    One can refer the fields without any prefix in the ListView. Also, each item is available as the context in the template. 
    The schema in DataSource is not generally required.

    After this everything worked beautifully.

    Cheers
    Abhishek Kant

     

  5. Shree
    Shree avatar
    4 posts
    Member since:
    Apr 2012

    Posted 18 May 2012 Link to this post

    @ Abhishek,

    Did you already worked with asmx webserive json data? 
  6. Abhishek
    Abhishek avatar
    7 posts
    Member since:
    Jul 2012

    Posted 18 May 2012 Link to this post

    Well i was using Odata via WCF Data Services. there was no involvement of ASMX service with JSON Support.
Back to Top
Kendo UI is VS 2017 Ready