gpt4 book ai didi

angularjs - 如何在 ng-grid 中使用分组设置聚合

转载 作者:行者123 更新时间:2023-12-04 11:08:48 25 4
gpt4 key购买 nike

我想查看网格中每个组的总数(或通常的任何聚合函数)。

这是在问题中请求并关闭的: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 = 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>'
};
}

关于angularjs - 如何在 ng-grid 中使用分组设置聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16015088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com