Home AngularJS table creation for dynamic number of columns
Post
Cancel

AngularJS table creation for dynamic number of columns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<head>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.bundle.min.js"></script>
    <script src="js/angular.min.js"></script>
</head>

<body ng-app="myApp">
<div ng-controller="MyCtrl">
    <div class="table-responsive" id="table1">
        <table class="table table-sm table-hover">
            <thead class="thead-light">
                <tr>
                    <th ng-repeat="column in cols"></th>
                </tr>
            </thead>
            <tr ng-repeat="row in rows">
                <td ng-repeat="column in cols"></td>
            </tr>
        </table>
    </div>
</div>
</body>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.rows = [
    {
        "#": "1", 
        "name": "aa", 
        "score": "3.8"
    }, 
    {
        "#": "2", 
        "name": "bb", 
        "score": "4.0"
    }, 
    {
        "#": "3", 
        "name": "cc", 
        "score": "3.6"
    }];
    $scope.cols = Object.keys($scope.rows[0]);
}

Reference

This post is licensed under CC BY 4.0 by the author.

Hide and display html elements

Understanding MapReduce with an example

Comments powered by Disqus.