From 927d43e7a53624f386bdf074e078db1888ca6e4a Mon Sep 17 00:00:00 2001 From: alancqueiroz <67958316+alancqueiroz@users.noreply.github.com> Date: Wed, 21 Oct 2020 11:19:20 -0300 Subject: [PATCH] fix: pass both tree parent nodes and children nodes when exporting Fix export all data to excel with treeview bug. Example: http://plnkr.co/edit/hFPAO6W3EW8nlzt2 fix #7127, fix #6819 --- packages/exporter/src/js/exporter.js | 21 ++++++++++++--------- packages/exporter/test/exporter.spec.js | 8 ++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) 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() {