title: How do i create a table with a variable amount of columns and dynamic titles in Angular? pref using ng-tables
body: <p>i am trying create a table from a set of data using ng-tables. The data might not be the same every time. For example, i have these data:</p>
  
  <pre><code>var data = [
  
      {name: "St.Gabriels",        MeaslesCR: 50, ANC: 30, OPD: 20, SCORE: 100},
      {name: "N'Lale",             MeaslesCR: 52, ANC: 33, OPD: 20, SCORE: 90},
      {name: "Centrum Hospital",   MeaslesCR: 20, ANC: 70, OPD: 30, SCORE: 80},
      {name: "Something Hospital", MeaslesCR: 20, ANC: 50, OPD: 30, SCORE: 70},
      {name: "Wohoo Clinic",       MeaslesCR: 50, ANC: 30, OPD: 40, SCORE: 60}];
  </code></pre>
  
  <p>But i may for example, not have MeaslesCR included.</p>
  
  <p>So how do i create a table without manually creating all the columns with their respective titles?</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>var indicators = [];
  
  //Getting indicator names
  angular.forEach(data[0], function(value, key){
      indicators.push(key);
  });
  
  $scope.getTitle = function(i){
      return indicators[i];
  }
  
  $scope.tableParams = new ngTableParams({
      page: 1,            // show first page
      count: 10          // count per page
  }, {
      total: data.length, // length of data
      getData: function($defer, params) {
          // use build-in angular filter
          var orderedData = params.sorting() ?
              $filter('orderBy')(data, params.orderBy()) :
              data;
          $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
      }
  });
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    &lt;table ng-table="tableParams" class="table"&gt;
          &lt;tr ng-repeat="user in $data"&gt;
              &lt;td data-title="getTitle($index)" sortable="Name"&gt;
                  {{user.name}} // pref user.getTitle($index)
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>The html code obviously only writes one cell, but can i make it write out "$data.length" amount of cells somehow(this case 5)?</p>
  
  <p>With dynamic titles using getTitle($index) or some other better alternative?</p>
  
  <p>Then fill these columns with their respective user.varValue(user.name, user.MeaslesCR ect)?</p>
  
  <p>I am sorry if my questions are a bit confusing, because i think i am a bit confused myself.</p>
  
  <p>Thanks alot.</p>