Skip to content

Commit 3597417

Browse files
committed
Merge pull request #3602 from PaulL1/treebase
Treebase
2 parents 4d9ec8b + b98433f commit 3597417

File tree

10 files changed

+100
-47
lines changed

10 files changed

+100
-47
lines changed

misc/tutorial/209_grouping.ngdoc

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,31 @@ function will stop working), and writes them to the console.
143143
};
144144

145145
$scope.getAggregates = function() {
146-
var aggregateInfo = {};
147-
var lastState;
148-
$scope.gridApi.grid.renderContainers.body.visibleRowCache.forEach( function(row) {
149-
if( row.groupHeader ) {
150-
if( row.groupLevel === 0 ){
151-
// in the format "xxxxx (10)", we want the xxxx and the 10
152-
if( match = row.entity.state.match(/(.+) \((\d+)\)/) ){
153-
aggregateInfo[ match[1] ] = { stateTotal: match[2] };
154-
lastState = match[1];
155-
}
156-
} else if (row.groupLevel === 1){
157-
if( match = row.entity.gender.match(/(.+) \((\d+)\)/) ){
158-
aggregateInfo[ lastState ][ match[1] ] = match[2];
146+
var aggregatesTree = [];
147+
var gender
148+
149+
var recursiveExtract = function( treeChildren ) {
150+
return treeChildren.map( function( node ) {
151+
var newNode = {};
152+
angular.forEach(node.row.entity, function( attributeCol ) {
153+
if( typeof(attributeCol.groupVal) !== 'undefined' ) {
154+
newNode.groupVal = attributeCol.groupVal;
155+
newNode.aggVal = attributeCol.value;
159156
}
157+
});
158+
newNode.otherAggregations = node.aggregations.map( function( aggregation ) {
159+
return { colName: aggregation.col.name, value: aggregation.value, type: aggregation.type };
160+
});
161+
if( node.children ) {
162+
newNode.children = recursiveExtract( node.children );
160163
}
161-
}
162-
});
163-
console.log(aggregateInfo);
164+
return newNode;
165+
});
166+
}
167+
168+
aggregatesTree = recursiveExtract( $scope.gridApi.grid.treeBase.tree );
169+
170+
console.log(aggregatesTree);
164171
};
165172
}])
166173
.filter('mapGender', function() {

misc/tutorial/215_treeView.ngdoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ are loaded only when that row is expanded. They have a 2 second delay to simula
5353
$scope.gridOptions = {
5454
enableSorting: true,
5555
enableFiltering: true,
56+
showTreeExpandNoChildren: true,
5657
columnDefs: [
5758
{ name: 'name', width: '30%' },
5859
{ name: 'gender', width: '20%' },
@@ -86,6 +87,7 @@ are loaded only when that row is expanded. They have a 2 second delay to simula
8687
data[0].$$treeLevel = 0;
8788
data[1].$$treeLevel = 1;
8889
data[10].$$treeLevel = 1;
90+
data[11].$$treeLevel = 1;
8991
data[20].$$treeLevel = 0;
9092
data[25].$$treeLevel = 1;
9193
data[50].$$treeLevel = 0;
@@ -100,6 +102,11 @@ are loaded only when that row is expanded. They have a 2 second delay to simula
100102
$scope.toggleRow = function( rowNum ){
101103
$scope.gridApi.treeBase.toggleRowTreeState($scope.gridApi.grid.renderContainers.body.visibleRowCache[rowNum]);
102104
};
105+
106+
$scope.toggleExpandNoChildren = function(){
107+
$scope.gridOptions.showTreeExpandNoChildren = !$scope.gridOptions.showTreeExpandNoChildren;
108+
$scope.gridApi.grid.refresh();
109+
};
103110
}]);
104111
</file>
105112

@@ -108,6 +115,7 @@ are loaded only when that row is expanded. They have a 2 second delay to simula
108115
<button id="expandAll" type="button" class="btn btn-success" ng-click="expandAll()">Expand All</button>
109116
<button id="toggleFirstRow" type="button" class="btn btn-success" ng-click="toggleRow(0)">Toggle First Row</button>
110117
<button id="toggleSecondRow" type="button" class="btn btn-success" ng-click="toggleRow(1)">Toggle Second Row</button>
118+
<button id="toggleExpandNoChildren" type="button" class="btn btn-success" ng-click="toggleExpandNoChildren()">Toggle Expand No Children</button>
111119
<div id="grid1" ui-grid="gridOptions" ui-grid-tree-view class="grid"></div>
112120
</div>
113121
</file>

misc/tutorial/401_AllFeatures.ngdoc

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ All features are enabled to get an idea of performance
3535
$scope.gridOptions.columnDefs = [
3636
{ name:'id', width:50 },
3737
{ name:'name', width:100 },
38-
{ name:'age', width:100, enableCellEdit: true, aggregationType:uiGridConstants.aggregationTypes.avg,
39-
cellTemplate: '<div class="ui-grid-cell-contents"><span>Age:{{COL_FIELD}}</span></div>' },
40-
{ name:'address.street', width:150, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Street:{{COL_FIELD}}</span></div>' },
41-
{ name:'address.city', width:150, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>City:{{COL_FIELD}}</span></div>' },
42-
{ name:'address.state', width:50, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>State:{{COL_FIELD}}</span></div>' },
43-
{ name:'address.zip', width:50, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Zip:{{COL_FIELD}}</span></div>' },
44-
{ name:'company', width:100, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Company:{{COL_FIELD}}</span></div>' },
45-
{ name:'email', width:100, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Email:{{COL_FIELD}}</span></div>' },
46-
{ name:'phone', width:200, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Phone:{{COL_FIELD}}</span></div>' },
47-
{ name:'about', width:300, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>AAbout:{{COL_FIELD}}</span></div>' },
48-
{ name:'friends[0].name', displayName:'1st friend', width:150, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Friend0:{{COL_FIELD}}</span></div>' },
49-
{ name:'friends[1].name', displayName:'2nd friend', width:150, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Friend1:{{COL_FIELD}}</span></div>' },
50-
{ name:'friends[2].name', displayName:'3rd friend', width:150, enableCellEdit: true, cellTemplate: '<div class="ui-grid-cell-contents"><span>Friend2:{{COL_FIELD}}</span></div>' },
38+
{ name:'age', width:100, enableCellEdit: true, aggregationType:uiGridConstants.aggregationTypes.avg },
39+
{ name:'address.street', width:150, enableCellEdit: true },
40+
{ name:'address.city', width:150, enableCellEdit: true },
41+
{ name:'address.state', width:50, enableCellEdit: true },
42+
{ name:'address.zip', width:50, enableCellEdit: true },
43+
{ name:'company', width:100, enableCellEdit: true },
44+
{ name:'email', width:100, enableCellEdit: true },
45+
{ name:'phone', width:200, enableCellEdit: true },
46+
{ name:'about', width:300, enableCellEdit: true },
47+
{ name:'friends[0].name', displayName:'1st friend', width:150, enableCellEdit: true },
48+
{ name:'friends[1].name', displayName:'2nd friend', width:150, enableCellEdit: true },
49+
{ name:'friends[2].name', displayName:'3rd friend', width:150, enableCellEdit: true },
5150
{ name:'agetemplate',field:'age', width:150, cellTemplate: '<div class="ui-grid-cell-contents"><span>Age 2:{{COL_FIELD}}</span></div>' },
5251
{ name:'Is Active',field:'isActive', width:150, type:'boolean' }
5352
];
@@ -67,7 +66,6 @@ All features are enabled to get an idea of performance
6766
$scope.callsPending--;
6867

6968
data.forEach(function(row){
70-
row.name = row.name + ' iter ' + i;
7169
row.id = i;
7270
i++;
7371
$scope.myData.push(row);

src/features/exporter/js/exporter.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -658,15 +658,15 @@
658658
*/
659659
getColumnHeaders: function (grid, colTypes) {
660660
var headers = [];
661-
var sourceColumns;
661+
var columns;
662662

663663
if ( colTypes === uiGridExporterConstants.ALL ){
664-
sourceColumns = grid.columns;
664+
columns = grid.columns;
665665
} else {
666-
sourceColumns = grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } );
666+
columns = grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } );
667667
}
668668

669-
sourceColumns.forEach( function( gridCol, index ) {
669+
columns.forEach( function( gridCol, index ) {
670670
if ( gridCol.colDef.exporterSuppressExport !== true &&
671671
grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){
672672
headers.push({
@@ -723,9 +723,9 @@
723723
*/
724724
getData: function (grid, rowTypes, colTypes) {
725725
var data = [];
726-
727726
var rows;
728-
727+
var columns;
728+
729729
switch ( rowTypes ) {
730730
case uiGridExporterConstants.ALL:
731731
rows = grid.rows;
@@ -741,12 +741,20 @@
741741
}
742742
break;
743743
}
744-
744+
745+
if ( colTypes === uiGridExporterConstants.ALL ){
746+
columns = grid.columns;
747+
} else {
748+
columns = grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } );
749+
}
750+
745751
rows.forEach( function( row, index ) {
746752

747753
if (row.exporterEnableExporting !== false) {
748754
var extractedRow = [];
749-
grid.columns.forEach( function( gridCol, index ) {
755+
756+
757+
columns.forEach( function( gridCol, index ) {
750758
if ( (gridCol.visible || colTypes === uiGridExporterConstants.ALL ) &&
751759
gridCol.colDef.exporterSuppressExport !== true &&
752760
grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){
@@ -757,11 +765,11 @@
757765
extractedRow.push(extractedField);
758766
}
759767
});
760-
768+
761769
data.push(extractedRow);
762770
}
763771
});
764-
772+
765773
return data;
766774
},
767775

src/features/grouping/js/grouping.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,9 @@
885885
for (var i = 0; i < renderableRows.length; i++ ){
886886
var row = renderableRows[i];
887887

888-
processingState.forEach( updateProcessingState );
888+
if ( row.visible ){
889+
processingState.forEach( updateProcessingState );
890+
}
889891
}
890892

891893
delete grid.grouping.oldGroupingHeaderCache;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@
10111011
}
10121012

10131013
// aggregate if this is a leaf node
1014-
if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
1014+
if ( ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) && row.visible ){
10151015
service.aggregate( grid, row, parents );
10161016
}
10171017

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div class="ui-grid-tree-base-row-header-buttons" ng-class="{'ui-grid-icon-minus-squared': grid.treeBase.expandAll, 'ui-grid-icon-plus-squared': !grid.treeBase.expandAll}" ng-click="headerButtonClick($event)">
1+
<div class="ui-grid-tree-base-row-header-buttons" ng-class="{'ui-grid-icon-minus-squared': grid.treeBase.numberLevels > 0 && grid.treeBase.expandAll, 'ui-grid-icon-plus-squared': grid.treeBase.numberLevels > 0 && !grid.treeBase.expandAll}" ng-click="headerButtonClick($event)">
22
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="ui-grid-tree-base-row-header-buttons" ng-class="{'ui-grid-tree-base-header': row.treeLevel > - 1}" ng-click="treeButtonClick(row, $event)">
2-
<i ng-class="{'ui-grid-icon-minus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || row.treeNode.children.length > 0 ) && row.treeNode.state === 'expanded', 'ui-grid-icon-plus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || row.treeNode.children.length > 0 ) && row.treeNode.state === 'collapsed'}" ng-style="{'padding-left': grid.options.treeIndent * row.treeLevel + 'px'}"></i>
1+
<div class="ui-grid-tree-base-row-header-buttons" ng-class="{'ui-grid-tree-base-header': row.treeLevel > -1 }" ng-click="treeButtonClick(row, $event)">
2+
<i ng-class="{'ui-grid-icon-minus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) && row.treeNode.state === 'expanded', 'ui-grid-icon-plus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) && row.treeNode.state === 'collapsed'}" ng-style="{'padding-left': grid.options.treeIndent * row.treeLevel + 'px'}"></i>
33
&nbsp;
44
</div>

src/js/core/directives/ui-grid-footer-cell.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
updateClass();
4848
}
4949

50+
$scope.col.updateAggregationValue();
51+
5052
// Watch for column changes so we can alter the col cell class properly
5153
/* shouldn't be needed any more, given track by col.name
5254
$scope.$watch('col', function (n, o) {

src/js/core/factories/GridOptions.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,37 @@ angular.module('ui.grid')
6969
* @name data
7070
* @propertyOf ui.grid.class:GridOptions
7171
* @description (mandatory) Array of data to be rendered into the grid, providing the data source or data binding for
72-
* the grid. The most common case is an array of objects, where each object has a number of attributes.
72+
* the grid.
73+
*
74+
* Most commonly the data is an array of objects, where each object has a number of attributes.
7375
* Each attribute automatically becomes a column in your grid. This array could, for example, be sourced from
74-
* an angularJS $resource query request. The array can also contain complex objects.
76+
* an angularJS $resource query request. The array can also contain complex objects, refer the binding tutorial
77+
* for examples of that.
78+
*
79+
* The most flexible usage is to set your data on $scope:
80+
*
81+
* `$scope.data = data;`
82+
*
83+
* And then direct the grid to resolve whatever is in $scope.data:
84+
*
85+
* `$scope.gridOptions.data = 'data';`
86+
*
87+
* This is the most flexible approach as it allows you to replace $scope.data whenever you feel like it without
88+
* getting pointer issues.
89+
*
90+
* Alternatively you can directly set the data array:
91+
*
92+
* `$scope.gridOptions.data = [ ];`
93+
* or
94+
*
95+
* `$http.get('/data/100.json')
96+
* .success(function(data) {
97+
* $scope.myData = data;
98+
* $scope.gridOptions.data = $scope.myData;
99+
* });`
100+
*
101+
* Where you do this, you need to take care in updating the data - you can't just update `$scope.myData` to some other
102+
* array, you need to update $scope.gridOptions.data to point to that new array as well.
75103
*
76104
*/
77105
baseOptions.data = baseOptions.data || [];

0 commit comments

Comments
 (0)