read datasource from local Json File

2 posts, 1 answers
  1. pcs
    pcs avatar
    6 posts
    Member since:
    Mar 2021

    Posted 17 Mar Link to this post

    Hi

        I need for an test to modify original

     dataSource: {
            type: "odata",
            transport: {
                read: "http://demos.kendoui.com/service/Northwind.svc/Employees"
            },
            pageSize: 6,
            serverPaging: true,
            serverSorting: true
        },

    By an local file with changed data

    I have tried without succes two change

    First

     dataSource: {
            transport: {
                type: "json",
                read: "http://demos.kendoui.com/service/Northwind.svc/Employees?$format=json"
            },

    second test

     dataSource: {
            transport: {
                type: "json",
                read: "Employees.json"
            },

    Where is my mistake ?

    Regards

  2. Answer
    Mihaela
    Admin
    Mihaela avatar
    44 posts

    Posted 19 Mar Link to this post

    Hi,

    Thank you for the code snippets.

    The loading of a local JSON data file in the Kendo UI DataSource component could be implemented as follows:

    1. Format the JSON data as JSON Array (array of JSON objects)
    var localData = [
    {
      "property1": "test value",
      "property2": test value 2
    }, { ... } ];

        2. Include the file on the HTML page:

    <script type="text/javascript" src="fileName.json"></script>

        3. Update the "transport'' configuration of the data source by specifying the "url" to point to the location of the data (the JSON Array):

    dataSource: {
      transport:{
          url: localData,
          type: "json",
          read:  function (e) {
            e.success(localData);
          }
      },
      ...
    }

    Would you please give a try of this example and let me know if it works properly at your end?

    Feel free to let me know if you need any further assistance.

     

    Regards, Mihaela Lukanova Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top