ngTable中的行数不正确

时间:2017-09-27 02:49:14

标签: angularjs ngtable

In this plunk我在{count: 3}中使用NgTableParams设置了每页3行的ngTable。相反,该表每页显示4行。如何解决这个问题?

HTML:

  <table ng-table-dynamic="tableParams with cols" class="table table-bordered table-hover">
    <thead>
      <tr>
        <th ng-repeat="col in cols" ng-style="{ 'color': col.color }">{{col.title}}</th>
      </tr>
    </thead>
    <tr ng-repeat="row in data">
      <td ng-repeat="col in cols" ng-style="{ 'color': col.color }" >{{row[col.nm]}}</td>
    </tr>
  </table>

使用Javascript:

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

app.controller('myCtl', function($scope,NgTableParams) {

      $scope.cols = [ 
        {nm:'uid', title:'User ID', color: 'blue'}, 
        {nm:'ugr', title: 'Group ID', color: 'red'} 
      ];


      $scope.data = [ 
        { uid: 'aaa',ugr: '222'},
        { uid: 'bbb', ugr: '111'},
        { uid: 'ccc',ugr: '222'},
        { uid: 'ddd', ugr: '111'}
      ];

      $scope.tableParams = new NgTableParams({count: 3}, 
                                   {dataset: $scope.data, counts: []});

});

1 个答案:

答案 0 :(得分:1)

你应该改变你的代码:

<tr ng-repeat="row in $data">
          <td ng-repeat="col in cols" ng-style="{ 'color': col.color }" >{{row[col.nm]}}</td>
        </tr>


$scope.tableParams = new NgTableParams({count: 3}, {data: $scope.data, counts: []});

原因是: 1,关于&#39; $ data&#39;,请参阅What is '$data' in ngtable's HTML page 2,关于&#39;数据&#39;替换数据集&#39;,请参阅Angular ng-table not loading dataset?