Skip to content

Commit ff54930

Browse files
committed
Merge pull request #5168 from angular-ui/3.x
Merge 3.x
2 parents 62d70a1 + 7d5a464 commit ff54930

File tree

13 files changed

+125
-92
lines changed

13 files changed

+125
-92
lines changed

src/features/auto-resize-grid/js/auto-resize.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
if (newGridHeight !== prevGridHeight || newGridWidth !== prevGridWidth) {
4242
uiGridCtrl.grid.gridHeight = newGridHeight;
4343
uiGridCtrl.grid.gridWidth = newGridWidth;
44+
uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevGridHeight, prevGridWidth, newGridHeight, newGridWidth);
4445

4546
$scope.$apply(function () {
4647
uiGridCtrl.grid.refresh()

src/features/expandable/js/expandable.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,13 @@
324324
compile: function () {
325325
return {
326326
pre: function ($scope, $elm, $attrs, uiGridCtrl) {
327-
if ( uiGridCtrl.grid.options.enableExpandableRowHeader !== false ) {
327+
uiGridExpandableService.initializeGrid(uiGridCtrl.grid);
328+
329+
if (!uiGridCtrl.grid.options.enableExpandable) {
330+
return;
331+
}
332+
333+
if (uiGridCtrl.grid.options.enableExpandableRowHeader !== false ) {
328334
var expandableRowHeaderColDef = {
329335
name: 'expandableButtons',
330336
displayName: '',
@@ -335,9 +341,9 @@
335341
};
336342
expandableRowHeaderColDef.cellTemplate = $templateCache.get('ui-grid/expandableRowHeader');
337343
expandableRowHeaderColDef.headerCellTemplate = $templateCache.get('ui-grid/expandableTopRowHeader');
338-
uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef);
344+
uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef, -90);
339345
}
340-
uiGridExpandableService.initializeGrid(uiGridCtrl.grid);
346+
341347
},
342348
post: function ($scope, $elm, $attrs, uiGridCtrl) {
343349
}
@@ -466,6 +472,10 @@
466472
return {
467473
pre: function ($scope, $elm, $attrs, controllers) {
468474

475+
if (!$scope.grid.options.enableExpandable) {
476+
return;
477+
}
478+
469479
$scope.expandableRow = {};
470480

471481
$scope.expandableRow.shouldRenderExpand = function () {
@@ -524,6 +534,11 @@
524534
priority: -200,
525535
scope: false,
526536
compile: function ($elm, $attrs) {
537+
538+
//todo: this adds ng-if watchers to each row even if the grid is not using expandable directive
539+
// or options.enableExpandable == false
540+
// The alternative is to compile the template and append to each row in a uiGridRow directive
541+
527542
var rowRepeatDiv = angular.element($elm.children().children()[0]);
528543
var expandedRowFillerElement = $templateCache.get('ui-grid/expandableScrollFiller');
529544
var expandedRowElement = $templateCache.get('ui-grid/expandableRow');

src/features/expandable/templates/expandableRowHeader.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class="ui-grid-row-header-cell ui-grid-expandable-buttons-cell">
33
<div
44
class="ui-grid-cell-contents">
5-
<i
5+
<i ng-if="!row.groupHeader==true"
66
ng-class="{ 'ui-grid-icon-plus-squared' : !row.isExpanded, 'ui-grid-icon-minus-squared' : row.isExpanded }"
77
ng-click="grid.api.expandable.toggleRowExpansion(row.entity)">
88
</i>

src/features/grouping/js/grouping.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@
619619
columns.sort(function(a, b){
620620
var a_group, b_group;
621621
if (a.isRowHeader){
622-
a_group = -1000;
622+
a_group = a.headerPriority;
623623
}
624624
else if ( typeof(a.grouping) === 'undefined' || typeof(a.grouping.groupPriority) === 'undefined' || a.grouping.groupPriority < 0){
625625
a_group = null;
@@ -628,7 +628,7 @@
628628
}
629629

630630
if (b.isRowHeader){
631-
b_group = -1000;
631+
b_group = b.headerPriority;
632632
}
633633
else if ( typeof(b.grouping) === 'undefined' || typeof(b.grouping.groupPriority) === 'undefined' || b.grouping.groupPriority < 0){
634634
b_group = null;

src/features/grouping/test/grouping.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
8585
it( 'will not move header columns', function() {
8686

8787
$timeout(function () {
88-
grid.addRowHeaderColumn({name:'aRowHeader'});
88+
grid.addRowHeaderColumn({name:'aRowHeader'}, -200);
8989
});
9090
$timeout.flush();
9191

src/features/selection/js/selection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@
667667
allowCellFocus: true
668668
};
669669

670-
uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef);
670+
uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef, 0);
671671
}
672672

673673
var processorSet = false;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@
461461
* @ngdoc object
462462
* @name showTreeRowHeader
463463
* @propertyOf ui.grid.treeBase.api:GridOptions
464-
* @description If set to false, don't create the row header. Youll need to programatically control the expand
464+
* @description If set to false, don't create the row header. You'll need to programmatically control the expand
465465
* states
466466
* <br/>Defaults to true
467467
*/
@@ -715,7 +715,7 @@
715715
};
716716

717717
rowHeaderColumnDef.visible = grid.options.treeRowHeaderAlwaysVisible;
718-
grid.addRowHeaderColumn( rowHeaderColumnDef );
718+
grid.addRowHeaderColumn( rowHeaderColumnDef, -100 );
719719
},
720720

721721

src/js/core/directives/ui-grid-menu.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,25 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
4343
templateUrl: 'ui-grid/uiGridMenu',
4444
replace: false,
4545
link: function ($scope, $elm, $attrs, uiGridCtrl) {
46-
var gridMenuMaxHeight;
4746

4847
$scope.dynamicStyles = '';
4948

50-
if (uiGridCtrl) {
49+
var setupHeightStyle = function(gridHeight) {
5150
// magic number of 30 because the grid menu displays somewhat below
5251
// the top of the grid. It is approximately 30px.
53-
gridMenuMaxHeight = uiGridCtrl.grid.gridHeight - 30;
54-
$scope.dynamicStyles = [
52+
var gridMenuMaxHeight = gridHeight - 30;
53+
$scope.dynamicStyles = [
5554
'.grid' + uiGridCtrl.grid.id + ' .ui-grid-menu-mid {',
56-
'max-height: ' + gridMenuMaxHeight + 'px;',
55+
'max-height: ' + gridMenuMaxHeight + 'px;',
5756
'}'
5857
].join(' ');
58+
};
59+
60+
if (uiGridCtrl) {
61+
setupHeightStyle(uiGridCtrl.grid.gridHeight);
62+
uiGridCtrl.grid.api.core.on.gridDimensionChanged($scope, function(oldGridHeight, oldGridWidth, newGridHeight, newGridWidth) {
63+
setupHeightStyle(newGridHeight);
64+
});
5965
}
6066

6167
$scope.i18n = {

src/js/core/factories/Grid.js

+43-33
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ angular.module('ui.grid')
272272
* @methodOf ui.grid.core.api:PublicApi
273273
* @description adds a row header column to the grid
274274
* @param {object} column def
275+
* @param {number} order Determines order of header column on grid. Lower order means header
276+
* is positioned to the left of higher order headers
275277
*
276278
*/
277279
self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn );
@@ -379,7 +381,7 @@ angular.module('ui.grid')
379381
* that have sorting on them, sorted in priority order.
380382
*
381383
* @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
382-
* @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of
384+
* @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of
383385
* columns with sorts on them, in priority order.
384386
*
385387
* @example
@@ -754,8 +756,14 @@ angular.module('ui.grid')
754756
* @description adds a row header column to the grid
755757
* @param {object} column def
756758
*/
757-
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef) {
759+
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order) {
758760
var self = this;
761+
762+
//default order
763+
if (order === undefined) {
764+
order = 0;
765+
}
766+
759767
var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self);
760768
rowHeaderCol.isRowHeader = true;
761769
if (self.isRTL()) {
@@ -774,7 +782,12 @@ angular.module('ui.grid')
774782
rowHeaderCol.enableFiltering = false;
775783
rowHeaderCol.enableSorting = false;
776784
rowHeaderCol.enableHiding = false;
785+
rowHeaderCol.headerPriority = order;
777786
self.rowHeaderColumns.push(rowHeaderCol);
787+
self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) {
788+
return a.headerPriority - b.headerPriority;
789+
});
790+
778791
self.buildColumns()
779792
.then( function() {
780793
self.preCompileCellTemplates();
@@ -836,9 +849,11 @@ angular.module('ui.grid')
836849
}
837850

838851
//add row header columns to the grid columns array _after_ columns without columnDefs have been removed
839-
self.rowHeaderColumns.forEach(function (rowHeaderColumn) {
840-
self.columns.unshift(rowHeaderColumn);
841-
});
852+
//rowHeaderColumns is ordered by priority so insert in reverse
853+
for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) {
854+
self.columns.unshift(self.rowHeaderColumns[j]);
855+
}
856+
842857

843858

844859
// look at each column def, and update column properties to match. If the column def
@@ -898,6 +913,19 @@ angular.module('ui.grid')
898913
});
899914
};
900915

916+
Grid.prototype.preCompileCellTemplate = function(col) {
917+
var self = this;
918+
var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col));
919+
html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
920+
921+
var compiledElementFn = $compile(html);
922+
col.compiledElementFn = compiledElementFn;
923+
924+
if (col.compiledElementFnDefer) {
925+
col.compiledElementFnDefer.resolve(col.compiledElementFn);
926+
}
927+
};
928+
901929
/**
902930
* @ngdoc function
903931
* @name preCompileCellTemplates
@@ -906,25 +934,12 @@ angular.module('ui.grid')
906934
*/
907935
Grid.prototype.preCompileCellTemplates = function() {
908936
var self = this;
909-
910-
var preCompileTemplate = function( col ) {
911-
var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col));
912-
html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
913-
914-
var compiledElementFn = $compile(html);
915-
col.compiledElementFn = compiledElementFn;
916-
917-
if (col.compiledElementFnDefer) {
918-
col.compiledElementFnDefer.resolve(col.compiledElementFn);
919-
}
920-
};
921-
922-
this.columns.forEach(function (col) {
937+
self.columns.forEach(function (col) {
923938
if ( col.cellTemplate ){
924-
preCompileTemplate( col );
939+
self.preCompileCellTemplate( col );
925940
} else if ( col.cellTemplatePromise ){
926941
col.cellTemplatePromise.then( function() {
927-
preCompileTemplate( col );
942+
self.preCompileCellTemplate( col );
928943
});
929944
}
930945
});
@@ -2363,18 +2378,13 @@ angular.module('ui.grid')
23632378

23642379
// We were given a column to scroll to
23652380
if (gridCol !== null) {
2366-
// This is the index of the row we want to scroll to, within the list of rows that can be visible
2381+
// This is the index of the column we want to scroll to, within the list of columns that can be visible
23672382
var seekColumnIndex = visColCache.indexOf(gridCol);
23682383

2369-
// Total vertical scroll length of the grid
2384+
// Total horizontal scroll length of the grid
23702385
var horizScrollLength = (self.renderContainers.body.getCanvasWidth() - self.renderContainers.body.getViewportWidth());
23712386

2372-
// Add the height of the native horizontal scrollbar to the scroll length, if it's there. Otherwise it will mask over the final row
2373-
// if (self.verticalScrollbarWidth && self.verticalScrollbarWidth > 0) {
2374-
// horizScrollLength = horizScrollLength + self.verticalScrollbarWidth;
2375-
// }
2376-
2377-
// This is the minimum amount of pixels we need to scroll vertical in order to see this column
2387+
// This is the minimum amount of pixels we need to scroll horizontal in order to see this column
23782388
var columnLeftEdge = 0;
23792389
for (var i = 0; i < seekColumnIndex; i++) {
23802390
var col = visColCache[i];
@@ -2389,9 +2399,9 @@ angular.module('ui.grid')
23892399

23902400
var horizScrollPixels, horizPercentage;
23912401

2392-
// If the scroll position we need to see the row is LESS than the top boundary, i.e. obscured above the top of the self...
2402+
// If the scroll position we need to see the column is LESS than the left boundary, i.e. obscured before the left of the self...
23932403
if (columnLeftEdge < leftBound) {
2394-
// Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
2404+
// Get the different between the left boundary and the required scroll position and subtract it from the current scroll position\
23952405
// to get the full position we need
23962406
horizScrollPixels = self.renderContainers.body.prevScrollLeft - (leftBound - columnLeftEdge);
23972407

@@ -2400,9 +2410,9 @@ angular.module('ui.grid')
24002410
horizPercentage = (horizPercentage > 1) ? 1 : horizPercentage;
24012411
scrollEvent.x = { percentage: horizPercentage };
24022412
}
2403-
// Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
2413+
// Otherwise if the scroll position we need to see the column is MORE than the right boundary, i.e. obscured after the right of the self...
24042414
else if (columnRightEdge > rightBound) {
2405-
// Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
2415+
// Get the different between the right boundary and the required scroll position and add it to the current scroll position
24062416
// to get the full position we need
24072417
horizScrollPixels = columnRightEdge - rightBound + self.renderContainers.body.prevScrollLeft;
24082418

0 commit comments

Comments
 (0)