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

read datasource from local Json File

1 Answer 695 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pcs
Top achievements
Rank 1
Veteran
pcs asked on 17 Mar 2021, 05:03 AM

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

1 Answer, 1 is accepted

Sort by
0
Accepted
Mihaela
Telerik team
answered on 19 Mar 2021, 02:47 PM

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/.

Tags
Grid
Asked by
pcs
Top achievements
Rank 1
Veteran
Answers by
Mihaela
Telerik team
Share this question
or