0

retrieving SharePoint list items by REST with

var app = angular.module('myApp', ['ngGrid']);

    app.controller('MyCtrl', function ($scope, $http) {

        $http.get('http://whereever/_api/web/lists/getByTitle("Tasks")/items').success(function (data) {
            $scope.items = data;
        });

        $scope.gridOptions = {
            data: 'items',
            columnDefs: [
            { field: 'Title', displayName: 'Title' },
            { field: 'Status', displayName: 'Status' }
            ]
        };
    });

the ng-grid on

<div ng-controller="MyCtrl">
        <div class="gridStyle" ng-grid="gridOptions"></div>
    </div>

just shows nothing. A simple json example like http://plnkr.co/edit/UndbtO?p=preview works. Is there any example showing me how to use a REST call on a SharePoint list and passing data to ng-grid?

0

Found a solution:

var myAngApp = angular.module('myApp', ['ngGrid']);
myAngApp.controller('MyCtrl', function ($scope, $http) {   
    $http({
        method: 'GET',
        url: "http://whereever/_api/web/lists/getByTitle("Tasks")/items",
        headers: { "Accept": "application/json;odata=verbose" }
    }).success(function (data) {
        $scope.items = data.d.results;
    }).error(function (data, status, headers, config) {   
        console.log(status);
    });

    $scope.gridOptions = {
        data: 'items',
        columnDefs: [
        { field: 'Title', displayName: 'Title' },
        { field: 'Status', displayName: 'Status' }
        ]
    };

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.