diff --git a/packages/exporter/src/js/exporter.js b/packages/exporter/src/js/exporter.js index edccf756f4..cb5679a220 100755 --- a/packages/exporter/src/js/exporter.js +++ b/packages/exporter/src/js/exporter.js @@ -952,21 +952,24 @@ * recurse down into the children to get to the raw data element * which is a row without children (a leaf). * @param {Node} aNode the tree node on the grid - * @returns {Array} an array of leaf nodes + * @returns {Array} an array with all child nodes from aNode */ getRowsFromNode: function(aNode) { var rows = []; - for (var i = 0; i 1 || nodeKeys[0] != 'children') { + rows.push(aNode); + } + + if (aNode && aNode.children && aNode.children.length > 0) { + for (var i = 0; i < aNode.children.length; i++) { + rows = rows.concat(this.getRowsFromNode(aNode.children[i])); + } } return rows; }, - /** * @ngdoc function * @name getDataSorted diff --git a/packages/exporter/test/exporter.spec.js b/packages/exporter/test/exporter.spec.js index 714a9af4bc..e2e911836f 100644 --- a/packages/exporter/test/exporter.spec.js +++ b/packages/exporter/test/exporter.spec.js @@ -871,6 +871,14 @@ describe('ui.grid.exporter', function() { {col1: 'a_4', col2: 'b_4', col3: 'c_4', children: []} ]); }); + it('should return partent rows when they have their own data', function() { + var bNode = {col1: 'a_1', col2: 'b_1', children: [{col1: 'a_2', col2: 'b_2', col3: 'c_2', children: []}]}; + + expect(uiGridExporterService.getRowsFromNode(bNode)).toEqual([ + {col1: 'a_1', col2: 'b_1', children: [{col1: 'a_2', col2: 'b_2', col3: 'c_2', children: []}]}, + {col1: 'a_2', col2: 'b_2', col3: 'c_2', children: []} + ]); + }); }); describe('getDataSorted', function() {