简体   繁体   中英

Angular ng-grid and JSON

I'm pretty new to Angular and im trying to display my JSON in ui-grid table. Anyways, since this is similar to ng-grid I hope someone can help me.

I have a JSON like this:

{
    Users: [
        username:'blabla',
        email:'bla@gmail.com',
        type:'admin',
        userId: [
            id:'1222'
        ]
    ],
    Teams: [
        teamName: 'team1',
        teamId: '123'
    ]
}

What I want is:

$scope.gridOptions = {
data: myDataSource, 
columnDefs: [{ field: 'Users.userName', displayName: 'userName', width: 90 }]

But im unable to access all the objects. I can access username only if I set my data to myDataSource.Users

This is a working example : http://jsfiddle.net/8jgpLn9h/

Controller :

var app = angular.module('app', ['ngTouch', 'ui.grid']);

app.controller('MainCtrl', ['$scope', function ($scope) {

  $scope.data = {
    Users : [{
            username : 'titi',
            email : 'bla@gmail.com',
            type : 'admin',
            userId : {
                id : '1222'
            }
        },{
            username : 'toto',
            email : 'toto@gmail.com',
            type : 'admin',
            userId : {
                id : '1'
            }
        }
    ],
    Teams : {
        teamName : 'team1',
        teamId : '123'
    }
 };
 $scope.gridOptions = { data: 'data.Users' };

}]);

HTML :

<div ng-app="app">
    <div ng-controller="MainCtrl">
        <div ui-grid="gridOptions" class="grid"></div>
    </div>
</div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM