print tables with dynamic columns angularjs and ngtable

1.3k views Asked by At

I'm using angularjs and ngtable and wish to print a table that is dynamically generated.

This is my code:

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]}}

My main problem is in the HTML view and print the structure. When the table is known columns I have no problems.

0

There are 0 answers