Skip to content

Commit 83af4a2

Browse files
committed
Merge pull request #5024 from rafaelb/expandable-extend
feat(expandable): Add 'expandRow' and 'getExpandedRows'
2 parents 6268333 + 005ca6a commit 83af4a2

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/features/expandable/js/expandable.js

+45-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
/**
101101
* @ngdoc object
102102
* @name ui.grid.expandable.api:GridRow
103-
*
103+
*
104104
* @description Additional properties added to GridRow when using the expandable module
105105
*/
106106
/**
@@ -186,6 +186,43 @@
186186
*/
187187
toggleAllRows: function() {
188188
service.toggleAllRows(grid);
189+
},
190+
/**
191+
* @ngdoc function
192+
* @name expandRow
193+
* @methodOf ui.grid.expandable.api:PublicApi
194+
* @description Expand the data row
195+
* @param {object} rowEntity gridOptions.data[] array instance
196+
*/
197+
expandRow: function (rowEntity) {
198+
var row = grid.getRow(rowEntity);
199+
if (row !== null && !row.isExpanded) {
200+
service.toggleRowExpansion(grid, row);
201+
}
202+
},
203+
/**
204+
* @ngdoc function
205+
* @name collapseRow
206+
* @methodOf ui.grid.expandable.api:PublicApi
207+
* @description Collapse the data row
208+
* @param {object} rowEntity gridOptions.data[] array instance
209+
*/
210+
collapseRow: function (rowEntity) {
211+
var row = grid.getRow(rowEntity);
212+
if (row !== null && row.isExpanded) {
213+
service.toggleRowExpansion(grid, row);
214+
}
215+
},
216+
/**
217+
* @ngdoc function
218+
* @name getExpandedRows
219+
* @methodOf ui.grid.expandable.api:PublicApi
220+
* @description returns all expandedRow's entity references
221+
*/
222+
getExpandedRows: function () {
223+
return service.getExpandedRows(grid).map(function (gridRow) {
224+
return gridRow.entity;
225+
});
189226
}
190227
}
191228
}
@@ -215,7 +252,7 @@
215252
if (angular.isUndefined(row.expandedRowHeight)){
216253
row.expandedRowHeight = grid.options.expandableRowHeight;
217254
}
218-
255+
219256
if (row.isExpanded) {
220257
row.height = row.grid.options.rowHeight + row.expandedRowHeight;
221258
}
@@ -253,6 +290,12 @@
253290
else {
254291
service.expandAllRows(grid);
255292
}
293+
},
294+
295+
getExpandedRows: function (grid) {
296+
return grid.rows.filter(function (row) {
297+
return row.isExpanded;
298+
});
256299
}
257300
};
258301
return service;

0 commit comments

Comments
 (0)