Skip to content

Commit 09f478c

Browse files
committed
fix(Pinning): Move rowStyle() to uiGridViewport
rowStyle() in GridRenderContainer was setting both row AND column offsets. The problem with that is pinned containers reference a different render container for their rows than their columns. Using the column margin-offset from the body container resulted in render issues. This change moves the rowStyle() function to uiGridViewport's controller, and it uses the rowContainer for the row offset and the colContainer for the column offset. Fixes #2821
1 parent d841b92 commit 09f478c

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

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

+29-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
return {
77
replace: true,
88
scope: {},
9+
controllerAs: 'Viewport',
910
templateUrl: 'ui-grid/uiGridViewport',
1011
require: ['^uiGrid', '^uiGridRenderContainer'],
1112
link: function($scope, $elm, $attrs, controllers) {
@@ -86,7 +87,34 @@
8687
}
8788
scrollEvent.fireScrollingEvent();
8889
});
89-
}
90+
},
91+
controller: ['$scope', function ($scope) {
92+
this.rowStyle = function (index) {
93+
var rowContainer = $scope.rowContainer;
94+
var colContainer = $scope.colContainer;
95+
96+
var styles = {};
97+
98+
if (index === 0 && rowContainer.currentTopRow !== 0) {
99+
// The row offset-top is just the height of the rows above the current top-most row, which are no longer rendered
100+
var hiddenRowWidth = (rowContainer.currentTopRow) * rowContainer.grid.options.rowHeight;
101+
102+
// return { 'margin-top': hiddenRowWidth + 'px' };
103+
styles['margin-top'] = hiddenRowWidth + 'px';
104+
}
105+
106+
if (colContainer.currentFirstColumn !== 0) {
107+
if (colContainer.grid.isRTL()) {
108+
styles['margin-right'] = colContainer.columnOffset + 'px';
109+
}
110+
else {
111+
styles['margin-left'] = colContainer.columnOffset + 'px';
112+
}
113+
}
114+
115+
return styles;
116+
};
117+
}]
90118
};
91119
}
92120
]);

src/js/core/directives/ui-pinned-container.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(function(){
22
'use strict';
33

4+
// TODO: rename this file to ui-grid-pinned-container.js
5+
46
angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) {
57
return {
68
restrict: 'EA',

src/js/core/factories/GridRenderContainer.js

-25
Original file line numberDiff line numberDiff line change
@@ -493,31 +493,6 @@ angular.module('ui.grid')
493493
this.setRenderedColumns(columnArr);
494494
};
495495

496-
GridRenderContainer.prototype.rowStyle = function (index) {
497-
var self = this;
498-
499-
var styles = {};
500-
501-
if (index === 0 && self.currentTopRow !== 0) {
502-
// The row offset-top is just the height of the rows above the current top-most row, which are no longer rendered
503-
var hiddenRowWidth = (self.currentTopRow) * self.grid.options.rowHeight;
504-
505-
// return { 'margin-top': hiddenRowWidth + 'px' };
506-
styles['margin-top'] = hiddenRowWidth + 'px';
507-
}
508-
509-
if (self.currentFirstColumn !== 0) {
510-
if (self.grid.isRTL()) {
511-
styles['margin-right'] = self.columnOffset + 'px';
512-
}
513-
else {
514-
styles['margin-left'] = self.columnOffset + 'px';
515-
}
516-
}
517-
518-
return styles;
519-
};
520-
521496
GridRenderContainer.prototype.headerCellWrapperStyle = function () {
522497
var self = this;
523498

src/templates/ui-grid/uiGridViewport.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="ui-grid-viewport" ng-style="colContainer.getViewPortStyle()">
22
<div class="ui-grid-canvas">
3-
<div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row" ng-style="rowContainer.rowStyle(rowRenderIndex)">
3+
<div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row" ng-style="Viewport.rowStyle(rowRenderIndex)">
44
<div ui-grid-row="row" row-render-index="rowRenderIndex"></div>
55
</div>
66
</div>

0 commit comments

Comments
 (0)