@@ -45,17 +45,19 @@ appears when you quickly scroll through the grid.
45
45
<file name="app.js">
46
46
var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.expandable', 'ui.grid.selection', 'ui.grid.pinning']);
47
47
48
- app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
49
- $scope.gridOptions = {
48
+ app.controller('MainCtrl', function MainCtrl($http, $log) {
49
+ var vm = this;
50
+
51
+ vm.gridOptions = {
50
52
expandableRowTemplate: 'expandableRowTemplate.html',
51
53
expandableRowHeight: 150,
52
54
//subGridVariable will be available in subGrid scope
53
55
expandableRowScope: {
54
56
subGridVariable: 'subGridScopeVariable'
55
57
}
56
- }
58
+ };
57
59
58
- $scope .gridOptions.columnDefs = [
60
+ vm .gridOptions.columnDefs = [
59
61
{ name: 'id' },
60
62
{ name: 'name'},
61
63
{ name: 'age'},
@@ -68,137 +70,149 @@ appears when you quickly scroll through the grid.
68
70
69
71
for(i = 0; i < data.length; i++){
70
72
data[i].subGridOptions = {
71
- columnDefs: [ {name:"Id" , field:"id"}, {name:" Name" , field:" name"} ],
73
+ columnDefs: [{name: 'Id' , field: 'id'}, {name: ' Name' , field: ' name'} ],
72
74
data: data[i].friends
73
- }
75
+ };
74
76
}
75
- $scope .gridOptions.data = data;
77
+ vm .gridOptions.data = data;
76
78
});
77
79
78
- $scope .gridOptions.onRegisterApi = function(gridApi){
79
- $scope .gridApi = gridApi;
80
+ vm .gridOptions.onRegisterApi = function(gridApi){
81
+ vm .gridApi = gridApi;
80
82
};
81
83
82
- $scope .expandAllRows = function() {
83
- $scope .gridApi.expandable.expandAllRows();
84
- }
84
+ vm .expandAllRows = function() {
85
+ vm .gridApi.expandable.expandAllRows();
86
+ };
85
87
86
- $scope.collapseAllRows = function() {
87
- $scope.gridApi.expandable.collapseAllRows();
88
- }
89
- }]);
88
+ vm.collapseAllRows = function() {
89
+ vm.gridApi.expandable.collapseAllRows();
90
+ };
90
91
91
- app.controller('SecondCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
92
- $scope.gridOptions = {
93
- enableRowSelection: true,
94
- expandableRowTemplate: 'expandableRowTemplate.html',
95
- expandableRowHeight: 150
96
- }
92
+ vm.toggleExpandAllBtn = function() {
93
+ vm.gridOptions.showExpandAllButton = !vm.gridOptions.showExpandAllButton;
94
+ };
95
+ });
97
96
98
- $scope.gridOptions.columnDefs = [
99
- { name: 'id', pinnedLeft:true },
100
- { name: 'name'},
101
- { name: 'age'},
102
- { name: 'address.city'}
103
- ];
104
-
105
- $http.get('/data/500_complex.json')
106
- .then(function(response) {
107
- var data = response.data;
108
-
109
- for(i = 0; i < data.length; i++){
110
- data[i].subGridOptions = {
111
- columnDefs: [ {name:"Id", field:"id"},{name:"Name", field:"name"} ],
112
- data: data[i].friends
113
- }
114
- }
115
- $scope.gridOptions.data = data;
116
- });
117
- }]);
118
-
119
- app.controller('ThirdCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
120
- $scope.gridOptions = {
121
- expandableRowTemplate: 'expandableRowTemplate.html',
122
- expandableRowHeight: 150,
123
- onRegisterApi: function (gridApi) {
124
- gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
125
- if (row.isExpanded) {
126
- row.entity.subGridOptions = {
127
- columnDefs: [
128
- { name: 'name'},
129
- { name: 'gender'},
130
- { name: 'company'}
131
- ]};
132
-
133
- $http.get('/data/100.json')
134
- .then(function(response) {
135
- row.entity.subGridOptions.data = response.data;
136
- });
137
- }
138
- });
139
- }
140
- }
97
+ app.controller('SecondCtrl', function SecondCtrl($http, $log) {
98
+ var vm = this;
141
99
142
- $scope.gridOptions.columnDefs = [
143
- { name: 'id', pinnedLeft:true },
144
- { name: 'name'},
145
- { name: 'age'},
146
- { name: 'address.city'}
147
- ];
148
-
149
- $http.get('/data/500_complex.json')
150
- .then(function(response) {
151
- $scope.gridOptions.data = response.data;
152
- });
153
- }]);
154
- app.controller('FourthCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
155
- $scope.gridOptions = {
156
- enableRowSelection: true,
157
- expandableRowTemplate: 'expandableRowTemplate.html',
158
- expandableRowHeight: 150
159
- }
100
+ vm.gridOptions = {
101
+ enableRowSelection: true,
102
+ expandableRowTemplate: 'expandableRowTemplate.html',
103
+ expandableRowHeight: 150
104
+ }
105
+
106
+ vm.gridOptions.columnDefs = [
107
+ { name: 'id', pinnedLeft:true },
108
+ { name: 'name'},
109
+ { name: 'age'},
110
+ { name: 'address.city'}
111
+ ];
112
+
113
+ $http.get('/data/500_complex.json')
114
+ .then(function(response) {
115
+ var data = response.data;
116
+
117
+ for(i = 0; i < data.length; i++) {
118
+ data[i].subGridOptions = {
119
+ columnDefs: [{name: 'Id', field: 'id'}, {name: 'Name', field: 'name'}],
120
+ data: data[i].friends
121
+ };
122
+ }
123
+ vm.gridOptions.data = data;
124
+ });
125
+ });
126
+
127
+ app.controller('ThirdCtrl', function ThirdCtrl($scope, $http, $log) {
128
+ var vm = this;
129
+
130
+ vm.gridOptions = {
131
+ expandableRowTemplate: 'expandableRowTemplate.html',
132
+ expandableRowHeight: 150,
133
+ onRegisterApi: function (gridApi) {
134
+ gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
135
+ if (row.isExpanded) {
136
+ row.entity.subGridOptions = {
137
+ columnDefs: [
138
+ { name: 'name'},
139
+ { name: 'gender'},
140
+ { name: 'company'}
141
+ ]};
160
142
161
- $scope.gridOptions.columnDefs = [
162
- { name: 'id', pinnedLeft:true },
163
- { name: 'name'},
164
- { name: 'age'},
165
- { name: 'address.city'}
166
- ];
167
-
168
- $http.get('/data/500_complex.json')
169
- .then(function(response) {
170
- var data = response.data;
171
-
172
- for(i = 0; i < data.length; i++){
173
- data[i].subGridOptions = {
174
- columnDefs: [ {name:"Id", field:"id"},{name:"Name", field:"name"} ],
175
- data: data[i].friends,
176
- disableRowExpandable : (i % 2 === 0)
177
- }
178
- }
179
- $scope.gridOptions.data = data;
180
- });
181
- }]);
143
+ $http.get('/data/100.json')
144
+ .then(function(response) {
145
+ row.entity.subGridOptions.data = response.data;
146
+ });
147
+ }
148
+ });
149
+ }
150
+ };
151
+
152
+ vm.gridOptions.columnDefs = [
153
+ { name: 'id', pinnedLeft:true },
154
+ { name: 'name'},
155
+ { name: 'age'},
156
+ { name: 'address.city'}
157
+ ];
158
+
159
+ $http.get('/data/500_complex.json')
160
+ .then(function(response) {
161
+ vm.gridOptions.data = response.data;
162
+ });
163
+ });
164
+
165
+ app.controller('FourthCtrl', function FourthCtrl($http, $log) {
166
+ var vm = this;
167
+
168
+ vm.gridOptions = {
169
+ enableRowSelection: true,
170
+ expandableRowTemplate: 'expandableRowTemplate.html',
171
+ expandableRowHeight: 150
172
+ };
173
+
174
+ vm.gridOptions.columnDefs = [
175
+ { name: 'id', pinnedLeft:true },
176
+ { name: 'name'},
177
+ { name: 'age'},
178
+ { name: 'address.city'}
179
+ ];
180
+
181
+ $http.get('/data/500_complex.json')
182
+ .then(function(response) {
183
+ var data = response.data;
184
+
185
+ for(i = 0; i < data.length; i++) {
186
+ data[i].subGridOptions = {
187
+ columnDefs: [{name: 'Id', field: 'id'}, {name: 'Name', field: 'name'}],
188
+ data: data[i].friends,
189
+ disableRowExpandable : (i % 2 === 0)
190
+ };
191
+ }
192
+ vm.gridOptions.data = data;
193
+ });
194
+ });
182
195
</file>
183
196
<file name="index.html">
184
- <div ng-controller="MainCtrl">
197
+ <div ng-controller="MainCtrl as main ">
185
198
<div class="control-group">
186
- <input type="button" class="btn btn-small" ng-click="expandAllRows()" value="Expand All"/>
187
- <input type="button" class="btn btn-small" ng-click="collapseAllRows()" value="Collapse All"/>
199
+ <button id="toggleVisibility" type="button" class="btn btn-sm btn-default" ng-click="main.toggleExpandAllBtn()">Toggle Expand All Visibility</button>
200
+ <button type="button" class="btn btn-sm btn-default" ng-click="main.expandAllRows()">Expand All</button>
201
+ <button type="button" class="btn btn-sm btn-default" ng-click="main.collapseAllRows()">Collapse All</button>
188
202
</div>
189
- <div ui-grid="gridOptions" ui-grid-pinning ui-grid-expandable class="grid"></div>
203
+ <div id="grid1" ui-grid="main. gridOptions" ui-grid-pinning ui-grid-expandable class="grid"></div>
190
204
</div>
191
205
Expandable rows works with checkboxes from selection and left pins
192
- <div ng-controller="SecondCtrl">
193
- <div ui-grid="gridOptions" ui-grid-pinning ui-grid-expandable ui-grid-selection class="grid"></div>
206
+ <div ng-controller="SecondCtrl as second ">
207
+ <div ui-grid="second. gridOptions" ui-grid-pinning ui-grid-expandable ui-grid-selection class="grid"></div>
194
208
</div>
195
209
Retrieve data for subGrid when expanding
196
- <div ng-controller="ThirdCtrl">
197
- <div ui-grid="gridOptions" ui-grid-expandable class="grid"></div>
210
+ <div ng-controller="ThirdCtrl as third ">
211
+ <div ui-grid="third. gridOptions" ui-grid-expandable class="grid"></div>
198
212
</div>
199
213
Toggle expand subGrid control
200
- <div ng-controller="FourthCtrl">
201
- <div ui-grid="gridOptions" ui-grid-expandable class="grid"></div>
214
+ <div ng-controller="FourthCtrl as fourth ">
215
+ <div ui-grid="fourth. gridOptions" ui-grid-expandable class="grid"></div>
202
216
</div>
203
217
</file>
204
218
<file name="main.css">
@@ -210,4 +224,33 @@ appears when you quickly scroll through the grid.
210
224
<file name="expandableRowTemplate.html">
211
225
<div ui-grid="row.entity.subGridOptions" style="height:150px;"></div>
212
226
</file>
227
+ <file name="scenario.js">
228
+ var gridTestUtils = require('../../test/e2e/gridTestUtils.spec.js'),
229
+ GridObjectTest = require('../../test/e2e/gridObjectTestUtils.spec.js'),
230
+ grid1 = new GridObjectTest('grid1');
231
+
232
+ describe('216 Expandable Grid', function() {
233
+ // Reload the page before each test if on Firefox. Chrome does it automatically.
234
+ gridTestUtils.firefoxReload();
235
+
236
+ it('should load the header values should be as expected', function() {
237
+ grid1.expectHeaderColumns(['Id', 'Name', 'Age', 'Address.City']);
238
+ });
239
+
240
+ describe('Toggle Expand All Visibility', function() {
241
+ var expandAllButton, emptyCellContent;
242
+
243
+ it('should display the expand all button by default', function() {
244
+ expandAllButton = element( by.css('#grid1 .ui-grid-expandable-buttons-cell .ui-grid-icon-button') );
245
+ expect(expandAllButton.isDisplayed()).toBe(true);
246
+ });
247
+ it('should hide the expand all button when the Toggle Expand All Visibility button is clicked', function() {
248
+ element( by.id('toggleVisibility') ).click();
249
+
250
+ emptyCellContent = element( by.css('#grid1 .ui-grid-expandable-buttons-cell .ui-grid-cell-empty') );
251
+ expect(emptyCellContent.isDisplayed()).toBe(true);
252
+ });
253
+ });
254
+ });
255
+ </file>
213
256
</example>
0 commit comments