Question

All of the examples that I can find of ng-grid Mater/Detail, such as the official demo at http://angular-ui.github.io/ng-grid/ do show Master / Detail, but they don't show it with two ng-grids.

How can I do that? I don't even know how to start. It looks like the grid is bound to $scope.gridOptions and $scope is bound to controller, so I don't see how to have two ng-grids in one controller.

Does that mean I need two controllers (connected by a service)?

Was it helpful?

Solution

The HTML

<body ng-controller="MyCtrl">
        <div class="gridStyle" ng-grid="fooGridOptions"></div>
        <div class="gridStyle" ng-grid="barGridOptions"></div>
</body>

the JS:

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.foo = [{name: "Moroni", age: 50},
                     {name: "Tiancum", age: 43},
                     {name: "Jacob", age: 27},
                     {name: "Nephi", age: 29},
                     {name: "Enos", age: 34}];
    $scope.bar = [{name: "Moroni", age: 50},
                     {name: "Foo", age: 43},
                     {name: "Bar", age: 27},
                     {name: "FooBar", age: 29},
                     {name: "JohnJohn", age: 34}];
    $scope.fooGridOptions = { data: 'foo' };
    $scope.barGridOptions = { data: 'bar' };
});

ng-grid looks in whichever object is passed with the directive(ng-grid="myOptionsObject"). In this case we only have the 'data' property set upon the object but other options are available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top