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

[Solved] Not able to populate grid with json

1 Answer 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shahriar
Top achievements
Rank 1
Shahriar asked on 10 Feb 2015, 01:13 AM
I am trying to test kendo grid in angular.js app. I am not able to load json to populate the grid. I keep hitting the error block in line 11 below. In my browser console, I see the file loading ok. 

Any pointers would be greatly appreciated!

01.appControllers.controller('LogsGridCtrl', function($scope, $http) {
02.    var ds = new kendo.data.DataSource({
03.        transport: {
04.            read: function(options) {
05.              $.ajax({
06.                url: "data/logs.json",
07.                dataType: "jsonp",
08.                success: function(result) {
09.                  options.success(result);
10.                },
11.                error: function(result) {
12.                  console.log('error loading logs');
13.                  options.error(result);
14.                }
15.              });
16.            }
17.        },
18.        pageSize: 10,
19.        schema  : {
20.            data: "sudo",
21.            parse : function(d) {
22.                for (var i = 0; i < d.length; i++) {
23.                    if (d[i].sudo) {
24.                        return d[i].sudo;
25.                    }
26.                }
27.                return [];
28.            }
29.        }
30. 
31.    });
32.    $scope.handleChange = function(data, dataItem, columns) {
33.      $scope.data = ds;
34.      $scope.columns = columns;
35.      $scope.dataItem = dataItem;
36.    };
37. 
38.    $scope.gridOptions = {
39.      dataSource: ds,
40.      selectable: "row"
41.    };
42.       
43.});

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 11 Feb 2015, 02:35 PM
Hello,

From the provided information it seems that you are trying to load the data from static file which most probably is not recognized as valid "jsonp" data. Could you please try to make the file to contain valid "json" data and change the "dataType" option in the ajax request as follows:

05.              $.ajax({
06.                url: "data/logs.json",
07.                dataType: "json",
08.                success: function(result) {
09.                  options.success(result);
10.                },
11.                error: function(result) {
12.                  console.log('error loading logs');
13.                  options.error(result);
14.                }
15.              });

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Shahriar
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or