Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

angularjs - How to set aggregation with grouping in ng-grid

I want to see totals (or generally any aggregation function) for each group in a grid.

This was requested and closed as done in issue: https://github.com/angular-ui/ng-grid/issues/95 (but unfortunately without any example).

I am able to redefine default template https://github.com/angular-ui/ng-grid/blob/master/src/templates/aggregateTemplate.html by aggregateTemplate config option. But I don't know how to extend it properly.

This template is evaluating in ng-grid scope and I don't know how to trigger my custom aggregation function. I want to create similar function as '''totalChildren''' (from https://github.com/angular-ui/ng-grid/blob/master/src/classes/aggregate.js )

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the answer: https://github.com/angular-ui/ng-grid/issues/290

For a completenes here is an example of my aggredate function:

function WorkLoadCtrl($scope, Issue, $routeParams, HttpCache) {
  $scope.issues = Issue.jql_search({jql: $routeParams.jql});

  $scope.aggFC = function (row) {
    var res = 0;

    var calculateChildren = function(cur) {
      var res = 0;
      var remaining;
      angular.forEach(cur.children, function(a) {
        remaining = a.getProperty('fields.timetracking.remainingEstimateSeconds');
        if (remaining) { res += remaining; }
      });
      return res;
    };

    var calculateAggChildren = function(cur) {
      var res = 0;
      res += calculateChildren(cur);
      angular.forEach(cur.aggChildren, function(a) {
        res += calculateAggChildren(a);
      });
      return res;
    };

    return (calculateAggChildren(row) / 3600).toFixed(2);
  }

  $scope.mySelections = [];
  $scope.gridOptions = {
    data: 'issues.issues',
    columnDefs: [
      {field:'key', displayName:'key'},
      {field:'fields.assignee.name', displayName:'Assignee'},
      {field:'fields.status.name', displayName:'Status'},
      {field:'fields.summary', displayName:'Summary'},
      {field:'fields.timetracking.remainingEstimate', displayName:'Remaining'},
    ],
    showFooter: true,
    showGroupPanel: true,
    enablePinning: true,
    enableColumnResize: true,
    enableColumnReordering: true,
    showColumnMenu: true,
    showFilter: true,
    //jqueryUIDraggable: true, bug: when used grouping stop work, but column reordering start to work:(
    selectedItems: $scope.mySelections,
    multiSelect: false,
    aggregateTemplate: '<div ng-click="row.toggleExpand()" ng-style="rowStyle(row)" class="ngAggregate"> <span class="ngAggregateText">{{row.label CUSTOM_FILTERS}} (count: {{row.totalChildren()}} {{AggItemsLabel}} Remaining: {{aggFC(row)}})</span> <div class="{{row.aggClass()}}"></div> </div>'
  };
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...