Fofole Fofole - 1 year ago 65
AngularJS Question

Angular js table with columns determined by object data

I have a list that contains objects that have variable data: = 0;
Object.map1 = [{key, value}, {key,value}, ...]

What I have is the unchanged data(like the ID) which I put as a column and then it's value in the row.

However, all the keys from the map need to be columns as well with the mapped value in the respective row for them, because each request to the service can return different data. So the output should be something like:

ID KEY1 KEY2 ...

I'm new to angular hope this makes sense.

EDIT: What I've been trying for columns:

<th ng-repeat="(column,v) in List.Objects[0].map1">
<a href="">{{column}}</a></th>

Answer Source

I tried my best to understand what you need, and I've come up with this example, I hope it answered your question:

angular.module('MyApp', []).controller('MyCtrl', function($scope) {

  $scope.List = [{
    id: 1,
    map1: [{
      key: 'key1',
      value: '789'
    }, {
      key: 'key2',
      value: '987'
  }, {
    id: 2,
    map1: [{
      key: 'key1',
      value: 'bbb'
    }, {
      key: 'key2',
      value: 'ddd'
<script src=""></script>

<table ng-app='MyApp' ng-controller='MyCtrl'>
    <th ng-repeat="(column,v) in List[0].map1">
  <tr ng-repeat="map in List">
    <td ng-repeat="(column,v) in map.map1">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download