代码之家  ›  专栏  ›  技术社区  ›  ps0604

ngTable dynamic with columns不显示列标题

  •  2
  • ps0604  · 技术社区  · 8 年前

    在这里 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>
    

    Java脚本:

    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});
    
    });
    
    1 回复  |  直到 5 年前
        1
  •  2
  •   Daniel Cottone    8 年前

    你错过了 title cols中的属性:

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

    See this plunkr .