@@ -7,10 +7,13 @@ We create a custom columnsProcessor to override the default aggregation that gro
7
7
setting a custom aggregation function so that we can aggregate data from a different column than the
8
8
one we're on.
9
9
10
+ We turn on the ability to select group headers, and write a callback on the selection event to select all
11
+ children of the selected rowHeader.
12
+
10
13
@example
11
14
<example module="app">
12
15
<file name="app.js">
13
- var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping', 'ui.grid.edit' ]);
16
+ var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.grouping', 'ui.grid.edit', 'ui.grid.selection' ]);
14
17
15
18
app.controller('MainCtrl', ['$scope', '$http', '$interval', 'uiGridGroupingConstants', '$filter', function ($scope, $http, $interval, uiGridGroupingConstants, $filter ) {
16
19
var setGroupValues = function( columns, rows ) {
@@ -39,6 +42,7 @@ one we're on.
39
42
40
43
$scope.gridOptions = {
41
44
enableFiltering: true,
45
+ enableGroupHeaderSelection: true,
42
46
columnDefs: [
43
47
{ name: 'name', width: '30%' },
44
48
{ name: 'gender', grouping: { groupPriority: 1 }, sort: { priority: 1, direction: 'asc' }, editableCellTemplate: 'ui-grid/dropdownEditor', width: '20%',
@@ -57,6 +61,19 @@ one we're on.
57
61
onRegisterApi: function( gridApi ) {
58
62
$scope.gridApi = gridApi;
59
63
$scope.gridApi.grid.registerColumnsProcessor( setGroupValues, 410 );
64
+ $scope.gridApi.selection.on.rowSelectionChanged( $scope, function ( rowChanged ) {
65
+ if ( typeof(rowChanged.treeLevel) !== 'undefined' && rowChanged.treeLevel > -1 ) {
66
+ // this is a group header
67
+ children = $scope.gridApi.treeBase.getRowChildren( rowChanged );
68
+ children.forEach( function ( child ) {
69
+ if ( rowChanged.isSelected ) {
70
+ $scope.gridApi.selection.selectRow( child.entity );
71
+ } else {
72
+ $scope.gridApi.selection.unSelectRow( child.entity );
73
+ }
74
+ });
75
+ }
76
+ });
60
77
}
61
78
};
62
79
@@ -96,7 +113,7 @@ one we're on.
96
113
97
114
<file name="index.html">
98
115
<div ng-controller="MainCtrl">
99
- <div id="grid1" ui-grid="gridOptions" ui-grid-grouping ui-grid-edit class="grid"></div>
116
+ <div id="grid1" ui-grid="gridOptions" ui-grid-grouping ui-grid-edit ui-grid-selection class="grid"></div>
100
117
</div>
101
118
</file>
102
119
0 commit comments