Skip to content

Commit 4843490

Browse files
Ubuntumportuga
Ubuntu
authored andcommitted
feat(tree-view): Supports recursive expanding
1 parent 145e366 commit 4843490

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/features/tree-base/js/tree-base.js

+34-12
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,10 @@
330330
* @methodOf ui.grid.treeBase.api:PublicApi
331331
* @description expand the immediate children of the specified row
332332
* @param {gridRow} row the row you wish to expand
333+
* @param {boolean} recursive true if you wish to expand the row's ancients
333334
*/
334-
expandRow: function (row) {
335-
service.expandRow(grid, row);
335+
expandRow: function (row, recursive) {
336+
service.expandRow(grid, row, recursive);
336337
},
337338

338339
/**
@@ -804,7 +805,7 @@
804805
if (row.treeNode.state === uiGridTreeBaseConstants.EXPANDED){
805806
service.collapseRow(grid, row);
806807
} else {
807-
service.expandRow(grid, row);
808+
service.expandRow(grid, row, false);
808809
}
809810

810811
grid.queueGridRefresh();
@@ -819,17 +820,38 @@
819820
*
820821
* @param {Grid} grid grid object
821822
* @param {GridRow} row the row we want to expand
823+
* @param {boolean} recursive true if you wish to expand the row's ancients
822824
*/
823-
expandRow: function ( grid, row ){
824-
if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
825-
return;
826-
}
825+
expandRow: function ( grid, row, recursive ){
826+
if ( recursive ){
827+
var parents = [];
828+
while ( row && typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 && row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ){
829+
parents.push(row);
830+
row = row.treeNode.parentRow;
831+
}
827832

828-
if ( row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ){
829-
row.treeNode.state = uiGridTreeBaseConstants.EXPANDED;
830-
grid.api.treeBase.raise.rowExpanded(row);
831-
grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
832-
grid.queueGridRefresh();
833+
if ( parents.length > 0 ){
834+
row = parents.pop();
835+
while ( row ){
836+
row.treeNode.state = uiGridTreeBaseConstants.EXPANDED;
837+
grid.api.treeBase.raise.rowExpanded(row);
838+
row = parents.pop();
839+
}
840+
841+
grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
842+
grid.queueGridRefresh();
843+
}
844+
} else {
845+
if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
846+
return;
847+
}
848+
849+
if ( row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ){
850+
row.treeNode.state = uiGridTreeBaseConstants.EXPANDED;
851+
grid.api.treeBase.raise.rowExpanded(row);
852+
grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
853+
grid.queueGridRefresh();
854+
}
833855
}
834856
},
835857

src/features/tree-base/test/tree-base.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ describe('ui.grid.treeBase uiGridTreeBaseService', function () {
125125
expect( expandCount ).toEqual(1);
126126
});
127127

128+
it( 'expandRow recursively', function() {
129+
expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' );
130+
131+
grid.api.treeBase.expandRow(grid.rows[4], true);
132+
treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) );
133+
expect( treeRows.length ).toEqual( 7, 'children of row 0, row 3 and row 4 are also visible' );
134+
expect( expandCount ).toEqual(3);
135+
});
136+
128137
it( 'expandRowChildren', function() {
129138
expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' );
130139

0 commit comments

Comments
 (0)