打印动态列angularjs和ngtable

时间:2015-06-13 16:41:17

标签: angularjs ngtable

我正在使用angularjs和ngtable,并希望打印一个动态生成的表。

这是我的代码:

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

app.controller('daCtrl', function($scope, ngTableParams, $http) 
{

   $scope.headers=[];
   $scope.data = []; 
   
  //----------------------example--------------------------
  //---$scope.header[{label: "value1"},{label: "value2"},{label: "value3"}]-----
  //---$scope.data[{value1: 1, value2: 2, value3: 3},{value1: 18, value2: 30, value3: 6}, {value1: 15, value2: 21, value3: 56},......]--------------
  //------- header y data are are dynamically generated
  

                $scope.tableParams = new ngTableParams({
                        page: 1,
                        count: 10,
                        filter: {
                            message: ''
                        },
                        sorting: {
                            asset: 'asc'
                        }
                    },
                    {
                        total: $scope.data.length,
                        counts:[],
                        getData: function($defer, params) {
                            var orderedData = params.sorting() ?
                                $filter('orderBy')($scope.data, params.orderBy()) :
                                $scope.data;

                            params.total(orderedData.length);
                            $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                        }

                    });


            });
        });
    
    
 });
<div ng-app="DL" ng-controller="daCtrl">
  
<table ng-table="tableParams" class="table table-striped table-hover table-bordered">
  <tr ng-repeat="a in $data | filter:search" style="text-align:center;">
  <td ng-repeat="col in headers" data-title="'{{col.label}}'" sortable="'tg1'">{{a.[col.label]}}</td>
   
                    </tr>
                </table>
  </div>

<!-- How to write {{a.[col.label]}}

我的主要问题是在HTML视图中打印结构。当表是已知列时我没有问题。

0 个答案:

没有答案