Skip to content

Commit 930d46d

Browse files
committed
Enh(grouping)Add events to grouping
`aggregationChanged` and `groupingChanged events added to the grouping publicApi Closes #3868
1 parent 2ff2cf0 commit 930d46d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

misc/tutorial/320_complex_grouping.ngdoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ children of the selected rowHeader.
9696
});
9797
}
9898
});
99+
100+
$scope.gridApi.grouping.on.aggregationChanged($scope, function(col){
101+
if ( col.treeAggregation.type ){
102+
$scope.lastChange = col.displayName + ' aggregated using ' + col.treeAggregation.type;
103+
} else {
104+
$scope.lastChange = 'Aggregation removed from ' + col.displayName;
105+
}
106+
});
107+
108+
$scope.gridApi.grouping.on.groupingChanged($scope, function(col){
109+
if ( col.grouping.groupPriority ){
110+
$scope.lastChange = col.displayName + ' grouped with priority ' + col.grouping.groupPriority;
111+
} else {
112+
$scope.lastChange = col.displayName + ' removed from grouped columns';
113+
}
114+
});
115+
99116
}
100117
};
101118

@@ -255,6 +272,7 @@ children of the selected rowHeader.
255272

256273
<file name="index.html">
257274
<div ng-controller="MainCtrl">
275+
<p ng-show="lastChange">Last grouping change: {{ lastChange }}</p>
258276
<div id="grid1" ui-grid="gridOptions" ui-grid-grouping ui-grid-edit ui-grid-selection class="grid" style="width:100%;"></div>
259277
</div>
260278
</file>

src/features/grouping/js/grouping.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,32 @@
157157
var publicApi = {
158158
events: {
159159
grouping: {
160+
/**
161+
* @ngdoc event
162+
* @eventOf ui.grid.grouping.api:PublicApi
163+
* @name aggregationChanged
164+
* @description raised whenever aggregation is changed, added or removed from a column
165+
*
166+
* <pre>
167+
* gridApi.grouping.on.aggregationChanged(scope,function(col){})
168+
* </pre>
169+
* @param {gridCol} col the column which on which aggregation changed. The aggregation
170+
* type is available as `col.treeAggregation.type`
171+
*/
172+
aggregationChanged: {},
173+
/**
174+
* @ngdoc event
175+
* @eventOf ui.grid.grouping.api:PublicApi
176+
* @name groupingChanged
177+
* @description raised whenever the grouped columns changes
178+
*
179+
* <pre>
180+
* gridApi.grouping.on.groupingChanged(scope,function(col){})
181+
* </pre>
182+
* @param {gridCol} col the column which on which grouping changed. The new grouping is
183+
* available as `col.grouping`
184+
*/
185+
groupingChanged: {}
160186
}
161187
},
162188
methods: {
@@ -652,6 +678,8 @@
652678
column.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn;
653679
column.treeAggregationFinalizerFn = service.groupedFinalizerFn;
654680

681+
grid.api.grouping.raise.groupingChanged(column);
682+
655683
grid.queueGridRefresh();
656684
},
657685

@@ -681,6 +709,8 @@
681709

682710
service.tidyPriorities( grid );
683711

712+
grid.api.grouping.raise.groupingChanged(column);
713+
684714
grid.queueGridRefresh();
685715
},
686716

@@ -712,6 +742,8 @@
712742
column.treeAggregationFn = aggregationDef.aggregationFn;
713743
column.treeAggregationFinalizerFn = aggregationDef.finalizerFn;
714744

745+
grid.api.grouping.raise.aggregationChanged(column);
746+
715747
grid.queueGridRefresh();
716748
},
717749

0 commit comments

Comments
 (0)