带列的ngTable动态不显示列标题

问题描述 投票:1回答:1

在这个plunk我有两个表,一个常规ng-table和一个ng-table-dynamic列。两者都指向相同的数据。

第二个表没有显示列标题,如何解决?

HTML

<br/> Table 1

<table ng-table="tableParams" class="table table-bordered table-hover">
    <tbody>
        <tr ng-repeat="u in data" ng-dblclick="alert('double click')">
            <td title="'User ID'">{{ u.uid }}</td>
            <td title="'Group'">{{ u.ugr }}</td>
        </tr>
    </tbody>
</table>

<br/> Table 2 

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

使用Javascript:

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

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

      $scope.cols = [ {nm:'uid'}, {nm:'ugr'} ];

      $scope.data = [ 
        { uid: 'User 1',ugr: 'Group 1'},
        { uid: 'User 2', ugr: 'Group 2'}
      ];

      $scope.tableParams = new NgTableParams({dataset: $scope.data});

});
javascript html json angularjs ngtable
1个回答
2
投票

您错过了cols中的title属性:

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

See this plunkr

© www.soinside.com 2019 - 2024. All rights reserved.