Javascript 使用AngularJS中的ng选项过滤器动态获取列的总和

Javascript 使用AngularJS中的ng选项过滤器动态获取列的总和,javascript,angularjs,Javascript,Angularjs,我有一个包含多个字段的表: <table id="sectiona" class="table" ng-show="showsum == 'true'" ng-init="reports.total = {}"> <thead> <tr> <th>Date</th> <th ng-show="groupBy.pubid == 'true' ">Pubid</th>

我有一个包含多个字段的表:

<table id="sectiona" class="table" ng-show="showsum == 'true'" ng-init="reports.total = {}">
  <thead>
    <tr>
      <th>Date</th>
      <th ng-show="groupBy.pubid == 'true' ">Pubid</th>
      <th ng-show="groupBy.sid == 'true' ">Sid</th>
      <th ng-show="groupBy.device == 'true' ">Device</th>
      <th ng-show="groupBy.seller == 'true' ">Seller</th>

      <th class="text-right" ng-show="groupBy.seller == 'false' ">Impressions</th>
      <th class="text-right">Clicks</th>
      <th class="text-right">Sales</th>
      <th class="text-right">GMV</th>
      <th class="text-right">Earnings</th>
      <th class="text-right">Earnings to Master</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="report in reports | orderBy:'_id.date.$date'" ng-show="( (groupBy.sid == 'true' && report._id.sid == data.singleSelect) || (groupBy.pubid == 'true' && report._id.pubid == data.singleSelect) || (groupBy.device == 'true' && report._id.device == data.singleSelect) || (groupBy.seller == 'true' && report._id.seller == data.singleSelect) ) || data.flag == 'true'">

      <td>{{ report._id.date.$date | date:"dd-MM-yyyy" }}</td>
      <td ng-show="groupBy.seller == 'true' ">{{ report._id.seller}}</td>
      <td ng-show="groupBy.pubid == 'true' ">{{ report._id.pubid}}</td>
      <td ng-show="groupBy.sid == 'true' ">{{ report._id.sid}}</td>
      <td ng-show="groupBy.device == 'true' ">{{ report._id.device}}</td>

      <td class="text-right" ng-show="groupBy.seller == 'false' ">{{ report.impressions | number:0 }}</td>
      <td ng-init="reports.total.clicks = reports.total.clicks + report.clicks" class="text-right">{{ report.clicks | number :0 }}</td>
      <td class="text-right">{{ report.sales | number : 0 }}</td>
      <td class="text-right">{{ report.gmv | number:0 }}</td>

      <td class="text-right">{{ report.earnings | number:0 }}</td>
      <td class="text-right" ng-repeat="info in pubsinfo" ng-show="info.pubid === user.pubProfile.pubid">
        {{ info.affshare * report.earnings | number : 0}}
      </td>
    </tr>
  </tbody>
</table>
这对sum有效,但问题是:我有一个过滤器选项,它也使用pubid、device、seller的ng选项,当我选择一个过滤器时,表中的行得到更新,但sum行没有得到更新

请帮助我获取基于可见行的动态总和。

查看以下内容:

1-使用此选项进行itens筛选:

ng-repeat='item in filtered = (items | filter:filterExpr)'
2-为总和可见值创建自定义筛选器后

myApp.filter("sumItens", function() {
    return function(data, index) {
        var s = 0;

        angular.forEach(data, function(item, i) {
            s += item.val;
        });
        return Math.ceil(s);
    };
});
var myApp=angular.module('myApp',[]);
函数MyCtrl($scope){
$scope.items=[{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2},
{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2},
{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2},
{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2}];
$scope.filterOptions=[“foo”、“bar”、“outher”];
}
myApp.filter(“sumItens”,function()){
返回函数(数据、索引){
var s=0;
如果(!data | |!data[0])返回soma;
角度.forEach(数据、功能(项目i){
s+=item.val;
});
返回Math.ceil(s);
};
})

过滤器:
2-为总和可见值创建自定义筛选器后

myApp.filter("sumItens", function() {
    return function(data, index) {
        var s = 0;

        angular.forEach(data, function(item, i) {
            s += item.val;
        });
        return Math.ceil(s);
    };
});
var myApp=angular.module('myApp',[]);
函数MyCtrl($scope){
$scope.items=[{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2},
{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2},
{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2},
{name:'foo',val:3},{name:'bar',val:5},{name:'outher',val:2}];
$scope.filterOptions=[“foo”、“bar”、“outher”];
}
myApp.filter(“sumItens”,function()){
返回函数(数据、索引){
var s=0;
如果(!data | |!data[0])返回soma;
角度.forEach(数据、功能(项目i){
s+=item.val;
});
返回Math.ceil(s);
};
})

过滤器: