Calculating values in column

Asked

Viewed 65 times

0

I have a doubt on how to calculate values that are in column, I was able to calculate the values in line, however, in columns I am not able, the need is to create subtotals of each column I have if anyone has any idea or some example of how to do this thank you.

  <table  class="table table-striped" height="100%">
            <thead>


                <tr>

                    <th width="170px" class="fileName alignCenter"><label class="titLabel">Date Event</label></th>
                    <th width="170px" class="fileName alignCenter"><label class="titLabel">Event Type</label></th>
                    <th width="150px"  class="alignCenter"><label class="titLabel">&nbsp;RE1A</label></th>
                    <th width="150px" class="alignCenter"><label class="titLabel">&nbsp;RE2A</label></th>
                    <th width="150px" class="alignCenter"><label class="titLabel">&nbsp;RE3A</label></th>
                    <th width="150px" class="alignCenter"><label class="titLabel">&nbsp;RE4A</label></th>
                    <th width="150px" class="alignCenter"><label class="titLabel">&nbsp;RE5A</label></th>
                    <th width="150px" class="alignCenter"><label class="titLabel">&nbsp;RE6A</label></th>
                    <th width="150px" class="alignCenter"><label class="titLabel">&nbsp;RE7A</label></th>
                    <th width="150px" class="alignCenter"><label class="titLabel">&nbsp;Total Event</label></th>
                </tr>


            </thead>
            <tbody>

                <tr id="no-results" ng-hide="{{noResults}}" ng-show="{{!noResults}}">
               </tr>
                <tr ng-repeat="output in result">
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.referenceDate | date:'dd/MM/yyyy'}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.eventType}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.re1A}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.re2A}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.re3A}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.re4A}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.re5A}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.re6A}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;{{output.re7A}}</label></td>
                    <td width="170px" class="alignCenter"><label>&nbsp;</label></td>

                </tr>
                  <tr  class="primary">
                  <td width="170px" class="alignCenter"><label>Total RE</label></td>
                  <td width="170px" class="alignCenter"><label>&nbsp;{{output.eventType}}</label></td>
                  </tr> 

            </tbody>


        </table>

recalling that I need to add up the RE’S values

1 answer

0


You just need to create a function that totals and then call it in your template:

$scope.totalizar = function(){
  var total = 0.0;

  for(var i = 0; i < $scope.result.length; i++){
    var output = $scope.result[i];
    total += (output.re1A + output.re2A + output.re3A + output.re4A + output.re5A + output.re6A + output.re7A);
  }

  return total;
}

And the call in the template:

<label>{{totalizar()}}</label>
  • I understood but as I would do to sum all the values of Re1a for example, I say all the values that are in this column ?

  • Ué, just put the variable you want to add into the function. Take a look at the code of the function and adapt to the attribute you want. In the example I are all, but if you want to add only one, just take the others

Browser other questions tagged

You are not signed in. Login or sign up in order to post.