From 005ca6a54c10ad60188cfb9529f92353f80cbd57 Mon Sep 17 00:00:00 2001 From: Rafael Borochov Date: Mon, 25 Jan 2016 15:50:06 +0200 Subject: [PATCH] feat(expandable): Add 'expandRow', 'collapseRow' and 'getExpandedRows' I need these features for a project for a project I am currently working on. add collapseRow method --- src/features/expandable/js/expandable.js | 47 +++++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/features/expandable/js/expandable.js b/src/features/expandable/js/expandable.js index ba54dc9989..6a27b8c7ad 100644 --- a/src/features/expandable/js/expandable.js +++ b/src/features/expandable/js/expandable.js @@ -100,7 +100,7 @@ /** * @ngdoc object * @name ui.grid.expandable.api:GridRow - * + * * @description Additional properties added to GridRow when using the expandable module */ /** @@ -186,6 +186,43 @@ */ toggleAllRows: function() { service.toggleAllRows(grid); + }, + /** + * @ngdoc function + * @name expandRow + * @methodOf ui.grid.expandable.api:PublicApi + * @description Expand the data row + * @param {object} rowEntity gridOptions.data[] array instance + */ + expandRow: function (rowEntity) { + var row = grid.getRow(rowEntity); + if (row !== null && !row.isExpanded) { + service.toggleRowExpansion(grid, row); + } + }, + /** + * @ngdoc function + * @name collapseRow + * @methodOf ui.grid.expandable.api:PublicApi + * @description Collapse the data row + * @param {object} rowEntity gridOptions.data[] array instance + */ + collapseRow: function (rowEntity) { + var row = grid.getRow(rowEntity); + if (row !== null && row.isExpanded) { + service.toggleRowExpansion(grid, row); + } + }, + /** + * @ngdoc function + * @name getExpandedRows + * @methodOf ui.grid.expandable.api:PublicApi + * @description returns all expandedRow's entity references + */ + getExpandedRows: function () { + return service.getExpandedRows(grid).map(function (gridRow) { + return gridRow.entity; + }); } } } @@ -215,7 +252,7 @@ if (angular.isUndefined(row.expandedRowHeight)){ row.expandedRowHeight = grid.options.expandableRowHeight; } - + if (row.isExpanded) { row.height = row.grid.options.rowHeight + row.expandedRowHeight; } @@ -253,6 +290,12 @@ else { service.expandAllRows(grid); } + }, + + getExpandedRows: function (grid) { + return grid.rows.filter(function (row) { + return row.isExpanded; + }); } }; return service;