从 UI - Grid 中的列脚注中读取总和值?

Read the sum value from the column footer in UI - Grid?

我目前正在尝试阅读我的列页脚以确保聚合的总和正好是 100。但是我找不到从网格函数中获取该值的方法。也许我错过了文档中的一个功能。有没有办法完成此操作,还是我必须手动遍历我的网格并对值求和?

您可以在列脚注中使用聚合来自动显示列中所有值的总和。

您可以像下面这样配置您的网格

$scope.gridOptions = {
    showGridFooter: true,
    showColumnFooter: true,
    enableFiltering: true,
    columnDefs: [
        { field: 'name', width: '13%' },
        { field: 'address.street',aggregationType: uiGridConstants.aggregationTypes.sum, width: '13%' },
        { field: 'age', aggregationType: uiGridConstants.aggregationTypes.avg, aggregationHideLabel: true, width: '13%' },
        { name: 'ageMin', field: 'age', aggregationType: uiGridConstants.aggregationTypes.min, width: '13%', displayName: 'Age for min' },
        { name: 'ageMax', field: 'age', aggregationType: uiGridConstants.aggregationTypes.max, width: '13%', displayName: 'Age for max' },
        { name: 'customCellTemplate', field: 'age', width: '14%', footerCellTemplate: '<div class="ui-grid-cell-contents" style="background-color: Red;color: White">custom template</div>' },
        { name: 'registered', field: 'registered', width: '20%', cellFilter: 'date', footerCellFilter: 'date', aggregationType: uiGridConstants.aggregationTypes.max }
    ],
    data: data,
    onRegisterApi: function(gridApi) {
            $scope.gridApi = gridApi;
    }
};

http://plnkr.co/edit/nv1eJAIyD5xNDn8XI6L9?p=preview

要从页脚获取值,前提是您知道列索引并引用了 gridApi。

$scope.getFooterValue = function()
{
  console.log($scope.gridApi);
  alert($scope.gridApi.grid.columns[2].getAggregationValue());
}