Angularjs 如何在ng表格中添加总计

Angularjs 如何在ng表格中添加总计,angularjs,ng-grid,date-arithmetic,Angularjs,Ng Grid,Date Arithmetic,我想知道我想实现的目标是否可能。基本上,我想要一个ng网格,它将计算一行的小计,我已经完成了以下工作: $scope.subTotal = function(row) { return (row.entity.price * row.entity.qty); }; 在我的ngGrid中: $scope.gridOptions1 = { data: 'orderContent.products', multiSelect: false, enableCell

我想知道我想实现的目标是否可能。基本上,我想要一个ng网格,它将计算一行的小计,我已经完成了以下工作:

$scope.subTotal = function(row) {

    return (row.entity.price * row.entity.qty);

};
在我的ngGrid中:

$scope.gridOptions1 = {

    data: 'orderContent.products',
    multiSelect: false,
    enableCellSelection: true,
    enableRowSelection: true,
    enableCellEdit: true,
    enableSorting: false,
    columnDefs:
        [
            {field:'remove', enableCellEdit: false, displayName:'Delete', cellTemplate: '<input class="btn btn-warning btn-xs" type="button" value="remove" ng-click="removeProduct(row)" />'},
            {field:'name', displayName: 'Name', enableCellEdit: true},
            {field:'price', displayName:'Price', enableCellEdit: true},
            {field:'qty', displayName:'Quantity', enableCellEdit: true},
            {field:'getTotal()', displayName:'Subtotal', enableCellEdit: false, cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text ng-class="{failed: row.getProperty(\'total\') < 72}">{{subTotal(row)}}</span></div>'}
        ]

};
$scope.gridOptions1={
数据:“orderContent.products”,
多选:错,
enableCellSelection:true,
enableRowSelection:true,
enableCellEdit:true,
启用排序:false,
columnDefs:
[
{字段:'remove',enableCellEdit:false,displayName:'Delete',cellTemplate:'},
{字段:'name',显示名称:'name',enableCellEdit:true},
{字段:'price',显示名:'price',enableCellEdit:true},
{字段:'qty',显示名称:'qty',enableCellEdit:true},
{字段:'getTotal()',显示名称:'Subtotal',enableCellEdit:false,cellTemplate:'{{Subtotal(行)}}}}
]
};
现在我有一个单元格,它有那一行的小计,并且工作正常。如何为所有行添加总计

请注意,表格是在用户单击按钮时填写的(初始状态为空)

我尝试了在
gridOptions1.ngGrid.entities.data
对象中循环。每次将产品添加到表中时都会触发循环/函数,但这不起作用

这是可以实现的吗

这是相似的

angular.forEach($scope.original_数据,函数(行){
row.getTotal=函数(){
返回getSum(行分数);
};
});
$scope.gridOptions={
数据:“原始数据”,
enableCellSelection:true,
enableRowSelection:false,
enableCellEdit:true,
columnDefs:[{字段:'name',显示名称:'name',enableCellEdit:false},
{field:'scores[0]',displayName:'scores1',enableCellEdit:true,cellTemplate:{{row.getProperty(col.field)}}},
{field:'scores[1]',displayName:'scores2',enableCellEdit:true,cellTemplate:{{row.getProperty(col.field)}}},
{field:'scores[2]',displayName:'scores3',enableCellEdit:true,cellTemplate:{{row.getProperty(col.field)}}},
{field:'scores[3]',displayName:'scores4',enableCellEdit:true,cellTemplate:{{row.getProperty(col.field)}}},
{field:'getTotal()',displayName:'Total',enableCellEdit:false,cellTemplate:'{{row.getProperty(col.field)}}}}}],,
启用排序:false,
};

一开始,我认为插件可以工作。。。我一直在关注github上ngGrid的FlexibleHeightPlugin,以实现一些外部逻辑。
 angular.forEach($scope.original_data, function (row) {
      row.getTotal = function () {
        return getSum(row.scores);
      };
    });

    $scope.gridOptions = {
            data: 'original_data',
            enableCellSelection: true,
            enableRowSelection: false,
            enableCellEdit: true,
            columnDefs: [{field:'name', displayName: 'Name', enableCellEdit: false},
            {field:'scores[0]', displayName:'Score1', enableCellEdit: true, cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text ng-class="{failed: row.getProperty(\'scores[0]\') < 18}">{{row.getProperty(col.field)}}</span></div>'},
            {field:'scores[1]', displayName:'Score2', enableCellEdit: true, cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text ng-class="{failed: row.getProperty(\'scores[1]\') < 18}">{{row.getProperty(col.field)}}</span></div>'},
            {field:'scores[2]', displayName:'Score3', enableCellEdit: true, cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text ng-class="{failed: row.getProperty(\'scores[2]\') < 18}">{{row.getProperty(col.field)}}</span></div>'},
            {field:'scores[3]', displayName:'Score4', enableCellEdit: true, cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text ng-class="{failed: row.getProperty(\'scores[3]\') < 18}">{{row.getProperty(col.field)}}</span></div>'},
            {field:'getTotal()', displayName:'Total', enableCellEdit: false, cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text ng-class="{failed: row.getProperty(\'total\') < 72}">{{row.getProperty(col.field)}}</span></div>'}],
            enableSorting: false,
        };