Angular ui-grid,如何限制或指定行数

时间:2014-08-13 11:36:02

标签: angularjs ng-grid

我在一个json中有数据,如下所示:

$scope.myData = [
          {name: "john", age: 25},
          {name: "anne", age: 21},
          {name: "joe", age: 22},
          {name: "mary", age: 31},
          {name: "stacey", age: 25},
          {name: "martin", age: 21},
          {name: "fred", age: 22},
          {name: "harry", age: 31}
];

如何将它们分成两个网格表,结果如下:

表1:

 __________
| name| age|
|----------|
| john| 25 |
| anne| 21 |
| joe | 22 |
| mary| 31 |
------------

表2:

 ____________
| name  | age|
|------------|
| stacey| 25 |
| martin| 21 |
| fred  | 22 |
| harry | 31 |
--------------

非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

请见http://plnkr.co/edit/lk1Y69?p=preview

将您的数据分成两部分

$scope.data1 = $scope.myData.splice(0,4);
$scope.data2 = $scope.myData.splice(0,4);

JS:

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
   $scope.myData = [
          {name: "john", age: 25},
          {name: "anne", age: 21},
          {name: "joe", age: 22},
          {name: "mary", age: 31},
          {name: "stacey", age: 25},
          {name: "martin", age: 21},
          {name: "fred", age: 22},
          {name: "harry", age: 31}
];

$scope.data1 = $scope.myData.splice(0,4);
$scope.data2 = $scope.myData.splice(0,4);

    $scope.gridOptions1 = { data: 'data1' };
     $scope.gridOptions2 = { data: 'data2' };
});

HTML:

<body ng-controller="MyCtrl"> <div class="gridStyle" ng-grid="gridOptions1"></div> <div class="gridStyle" ng-grid="gridOptions2"></div> </body>