ODATA Source Non JSONP

45 posts, 0 answers
  1. Ashwat
    Ashwat avatar
    6 posts
    Member since:
    Jul 2012

    Posted 28 Feb 2012 Link to this post

    The solution posted here works for me.

    Note the commented sections in odata.js file
    transports: {
    odata: {
    read: {
    cache: true, // to prevent jQuery from adding cache buster
    dataType: "jsonp"
    //jsonpCallback: "callback", //required by OData
    //jsonp: false
    //jsonp: "$callback"
    },

    parameterMap: function(options, type) {
    type = type || "read";

    var params = {
    //$format: "json",
    $inlinecount: "allpages"
    },
    option,
    dataType = (this.options || defaultDataType)[type].dataType;


    I am not able to attach the file in this thread...

  2. Clint
    Clint avatar
    56 posts
    Member since:
    Feb 2011

    Posted 28 Feb 2012 Link to this post

    Ashwat, thanks for the quick reply. 

    Got it working.
  3. Ashwat
    Ashwat avatar
    6 posts
    Member since:
    Jul 2012

    Posted 01 Mar 2012 Link to this post

    Clint,

    Could you share the modified odata file for the latest version of Kendo. I upgraded and it stopped working for me too and I am not able to figure out what I am missing.

    Thanks
  4. Kamil
    Kamil avatar
    1 posts
    Member since:
    Feb 2012

    Posted 02 Mar 2012 Link to this post

    Hi all,

    I was able to get the data from a SharePoint as you all have suggested. I'm using the kendo.all.js with the soem changes (removing $format=json and call back)

    Now i am trying to create a new record row and update the back end list. But when i click on Add new record, it gives and javascript error saying "Cannot read property '__count' of undefined" when i inspect my results received (json result from SharePoint service) i dont see a __count property there. Am i missing something here?
    Simply i want to create a new record and update it in SharePoint back end, and also want to do update on existing items.

    Thanks in advance for your all help.
  5. Clint
    Clint avatar
    56 posts
    Member since:
    Feb 2011

    Posted 02 Mar 2012 Link to this post

    Hey all, I'm actually using the exact same code that Ashwat posted above.  I'm also running the Q1 beta now and it's working fine.

    Note -- You need to make sure to reference each kendo js file singularly.  Note Rainer's post above.

    Here's the end of mine...
    extend(true, kendo.data, {
          schemas: {
              odata: {
                  type: "json",
                  data: "d.results",
                  total: "d.__count"
              }
          },
          transports: {
              odata: {
                  read: {
                      cache: true, // to prevent jQuery from adding cache buster
                      dataType: "jsonp",
                   //   jsonp: "$callback"
                  },
                  parameterMap: function(options, type) {
                      type = type || "read";
     
                      var params = {
                          //    $format: "json",
                              $inlinecount: "allpages"
                          },
                          option,
                          dataType = (this.options || defaultDataType)[type].dataType;
     
                      options = options || {};
     
                      for (option in options) {
                          if (mappers[option]) {
                              mappers[option](params, options[option]);
                          } else {
                              params[option] = options[option];
                          }
                      }
                      return params;
                  }
              }
          }
      });

    I use a content editor web part with a content link to reference a separate file.  Here's what I have in that file..... EXACTLY, only modifying the URL.

    <link href="/_layouts/assets/kendoui/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="/_layouts/assets/kendoui/styles/kendo.default.min.css" rel="stylesheet" />
    <script src="/_layouts/assets/kendoui/source/js/jquery.js" type="text/javascript"></script>
    <script src="/_layouts/assets/kendoui/source/js/jquery.tmpl.js" type="text/javascript"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.core.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.model.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.data.js"></script>  
    <script src="/_layouts/assets/kendoui/source/js/kendo.data.odata.js" type="text/javascript"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.grid.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.list.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.pager.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.sortable.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.filtermenu.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.popup.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.selectable.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.dropdownlist.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.numerictextbox.js"></script>
    <script src="/_layouts/assets/kendoui/source/js/kendo.calendar.js"></script>  
    <script src="/_layouts/assets/kendoui/source/js/kendo.datepicker.js"></script>
     
     
    <div id="grid"></div>
     
     
    <script>
     
    $(document).ready(function () {
     
      var ds = new kendo.data.DataSource({
        type: "odata",
        transport: {
          read: {
            dataType: "json"
          },
     
        },
     
        schema: {
          data: "d.results",
          model: {
            fields:
            {
              Title: { type: "string" },
              Id: { type: "number" },
            
            }
          }
        },
     
      });
       
      $("#grid").kendoGrid({
        dataSource: ds,
     
        columns:
        [
        { field: "Title", title: "Title"},
      { field: "Id", title: "Id"},
     
      ],
     
    });
     
    });
    </script>

    The above looks at a document library called "Documents" and returns the Title and Id.  You could point to a regular list instead.  I highly recommend starting off by just pulling back Title, or Title and Id, just to make sure everything works.  I also always start off using a grid, that way I know the datasource and JSON is correct.
  6. Clint
    Clint avatar
    56 posts
    Member since:
    Feb 2011

    Posted 02 Mar 2012 Link to this post

    Kamil, I haven't been able to add a new record to a list yet, either.  If you get it figured out, post up how you did it.  I will as well.
  7. Clint
    Clint avatar
    56 posts
    Member since:
    Feb 2011

    Posted 10 Mar 2012 Link to this post

    Anybody figure out how to update or delete a Sharepoint list item yet?
  8. Ondřej
    Ondřej avatar
    1 posts
    Member since:
    Mar 2012

    Posted 24 Mar 2012 Link to this post

    I have added crude support for updating(creating) OData JSON data sources by following steps in this thread for creating the odataCors data source and then configuring the update transport as such:

    transports: {
        odataCors: {
           update: {
                        type: "POST",
                        dataType: "json",
                        data: "",              
                        contentType: "application/json",
                        beforeSend: function(xhr, s) { s.data = JSON.stringify($.parseQueryString(s.data)); }
                    },
            }
    }

    You then configure your data source:
    var ds = new kendo.data.DataSource({
        type: "odataCors",
        transport: {
          read: baseUri+"d/Contacts",
          update: { url: baseUri+"d/Contacts" }
        }
      });

    Full odataCors source included (bear in mind that it is just a really quick example, not full fledged working code...). 
  9. Qloud Pty Ltd
    Qloud Pty Ltd avatar
    17 posts
    Member since:
    Sep 2011

    Posted 25 Mar 2012 Link to this post

    Hi,

    I've tried with LightSwitch OData and it didn't work with kendo UI as Json format conversion required.

    Anyone found the solution, how to integrate LS OData services to Kendo UI.

    I've tried all ways 1) kendo.data.odataCors.js  and it didn't worked.

    Please suggest the working sample for calling LS Odata.


    Regards
    Rama
  10. Jo
    Jo avatar
    5 posts
    Member since:
    Jul 2012

    Posted 28 Aug 2012 Link to this post

    I am trying to test Kendo UI grid with one of my Sharepoint list as a datasource. I have the codes almost similar to what everybody posted here. When I run the code I can see the grid however, it doesn't pull the SP list data into the grid. I did check the site URL and it looks fine, I can see all my lists when i do http://localhost/_vti_bin/ListData.svc. and i can see all the title data when i do http://localhost/_vti_bin/ListData.svc/mylist in Kendo code.
    If any one has working Kendo code to get the sharepoint list as a datasource .. please help me..

     

     

     

  11. John Thompson
    John Thompson avatar
    44 posts
    Member since:
    Dec 2009

    Posted 16 Sep 2012 Link to this post

    I played around with this some today since I am getting involved a lot with SharePoint 2010.  I used the shell from the demo for XML data to get me started and I can get results from the SharePoint list in XML feed format.  I put my test page (kendoUIgrid.aspx) in the Site Assets to avoid cross domain issues and loaded scripts and styles likewise.

    The problem comes when specifying the binding path for a field in the model when using schema.data: "/feed/entry".  

    I used "fields: { title: "content/m:properties/d:Title/text() ..." but this generates a error in the Kendo dataSource definition complaining of a missing ")".  Of course, normal X-Path definitions work just fine.  Just not when there's a namespace prefix as in "m" and "d" above.  My guess us the colon (":") throws the kendo.expr() function generator a knuckle ball and it swings and misses.  

    If you don't have to use namespace prefixes the dataSource is happy as in id: "id/text()" which renders as the Url to the specific list item.

    Can Telerik help us out on how to specify namespace prefixes for Xml return data?

  12. John
    John avatar
    11 posts
    Member since:
    Sep 2011

    Posted 16 Nov 2012 Link to this post

    Does anyone have an update to this thread?
    - The 3rd quarter release appears to have new syntax, is there an update to the odata js hack?
    - Has anyone been able to make this work with lightswitch?

    I can't the lightswitch data to appear in the grid using the latest bits from lightswitch and kendoui..

    Thanks for your help,

    jb
  13. Jack
    Jack avatar
    1 posts
    Member since:
    Nov 2012

    Posted 23 Nov 2012 Link to this post

    Having the same issue as John posted, Im using 2012Q3 release and although it works when the xml fragment doesnt contain any namespaces i cant get the dataSource to parse my xml correctly when it contains namespaces
    . ie. can we get some help in how to specify embedded namespace ie data: "/books/myns:book" where myns is a namespace urn
  14. DanKline
    DanKline avatar
    4 posts
    Member since:
    Dec 2007

    Posted 09 Jun 2013 Link to this post

    This is a year old now.  I can't believe that no one has published a simple example.  Come on folks, we are in this together.  Someone has to have a simple example with full CRUD against SharePoint 2010 REST services.
  15. Ashwat
    Ashwat avatar
    2 posts
    Member since:
    Jun 2012

    Posted 10 Jun 2013 Link to this post

    Hi
    SP2013 works well with latest kendo build out of the box with no customizations.
    For 2010, instead of modifying the Kendo api, I have found the following solution works with latest kendo build.

    Add the following jquery code to your js.

    $(document).ajaxSend(function (e, jqxhr, settings) {
    if (settings.url.toLowerCase().indexOf("/_vti_bin/listdata.svc".toLowerCase()) >= 0) {
    jqxhr.setRequestHeader("Accept", "application/json");
    }
    });

    For a more detailed explanation, refer to this link https://community.dynamics.com/crm/b/zhongchenzhoustipstricksandportaldevelopment/archive/2012/05/20/how-to-use-kendo-ui-datasource-kendo-ui-grid-with-dynamics-crm-2011-rest-endpoint.aspx 

    It is relevant for MS Dynamics but works for SharePoint as well.


Back to Top