如何在 ng-grid 中使用分组设置聚合 [英] How to set aggregation with grouping in ng-grid
问题描述
我想查看网格中每个组的总数(或通常的任何聚合函数).
这是在问题中请求并关闭的:https://github.com/angular-ui/ng-grid/issues/95(但遗憾的是没有任何示例).
我可以重新定义默认模板 https://github.com/angular-ui/ng-grid/blob/master/src/templates/aggregateTemplate.html 通过 aggregateTemplate
配置选项.但我不知道如何正确扩展它.
此模板正在 ng-grid 范围内进行评估,我不知道如何触发我的自定义聚合函数.我想创建与 '''totalChildren''' 类似的函数(来自 https://github.com/angular-ui/ng-grid/blob/master/src/classes/aggregate.js)
有什么想法吗?
我找到了答案:https://github.com/angular-ui/ng-grid/issues/290
为了完整起见,这里是我的聚合函数的一个例子:
function WorkLoadCtrl($scope, Issue, $routeParams, HttpCache) {$scope.issues = Issue.jql_search({jql: $routeParams.jql});$scope.aggFC = 函数(行){无功res = 0;var calculateChildren = function(cur) {无功res = 0;剩余变量;angular.forEach(cur.children, function(a) {剩余 = a.getProperty('fields.timetracking.remainingEstimateSeconds');如果(剩余){ res +=剩余;}});返回资源;};var calculateAggChildren = function(cur) {无功res = 0;res += calculateChildren(cur);angular.forEach(cur.aggChildren, function(a) {res += calculateAggChildren(a);});返回资源;};返回 (calculateAggChildren(row)/3600).toFixed(2);}$scope.mySelections = [];$scope.gridOptions = {数据:'issues.issues',列定义:[{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'},],显示页脚:真实,showGroupPanel: 真,启用固定:真,enableColumnResize: 真,enableColumnReordering: true,显示列菜单:真,显示过滤器:真,//jqueryUIDraggable: true, bug: 当使用分组停止工作,但列重新排序开始工作:(selectedItems: $scope.mySelections,多选:假,聚合模板:'<div ng-click="row.toggleExpand()" ng-style="rowStyle(row)" class="ngAggregate"><span class="ngAggregateText">{{row.label CUSTOM_FILTERS}}(计数:{{row.totalChildren()}} {{AggItemsLabel}} 剩余:{{aggFC(row)}})</span><div class="{{row.aggClass()}}"></div>
'};}
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?
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>'
};
}
这篇关于如何在 ng-grid 中使用分组设置聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!