Skip to content

Commit a335b92

Browse files
committed
fix(Grid): Avoid too-early header height calc
renderContainers with no canvasWidth were having their heights calculated. If their columns were wrapping around it would mean too large of a height on that renderContainer, and thus would be propogated to ALL the other containers (i.e. pinned containers).
1 parent 91bf06f commit a335b92

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/features/cellnav/js/cellnav.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,8 @@
745745
* @restrict A
746746
* @description Stacks on top of ui.grid.uiGridCell to provide cell navigation
747747
*/
748-
module.directive('uiGridCell', ['$timeout', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants',
749-
function ($timeout, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants) {
748+
module.directive('uiGridCell', ['$timeout', '$document', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants',
749+
function ($timeout, $document, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants) {
750750
return {
751751
priority: -150, // run after default uiGridCell directive and ui.grid.edit uiGridCell
752752
restrict: 'A',
@@ -772,7 +772,12 @@
772772
rowCol.col === $scope.col) {
773773
setFocused();
774774

775-
if (rowCol.hasOwnProperty('eventType') && rowCol.eventType === uiGridCellNavConstants.EVENT_TYPE.KEYDOWN) {
775+
if (
776+
// This cellNav event came from a keydown event so we can safely refocus
777+
(rowCol.hasOwnProperty('eventType') && rowCol.eventType === uiGridCellNavConstants.EVENT_TYPE.KEYDOWN)
778+
// The focus has gone to the body element, because we've probably wrapped around
779+
// ($document.activeElement === $document.body)
780+
) {
776781
$elm.find('div')[0].focus();
777782
}
778783
}

src/features/edit/js/gridEdit.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@
394394
$elm.on('keydown', beginEditKeyDown);
395395
if ($scope.col.colDef.enableCellEditOnFocus) {
396396
$elm.find('div').on('focus', beginEditFocus);
397-
// $elm.find('div').on('click', beginEditFocus);
398397
}
399398
}
400399

@@ -403,7 +402,6 @@
403402
$elm.off('keydown', beginEditKeyDown);
404403
if ($scope.col.colDef.enableCellEditOnFocus) {
405404
$elm.find('div').off('focus', beginEditFocus);
406-
// $elm.find('div').off('click', beginEditFocus);
407405
}
408406
}
409407

@@ -418,6 +416,9 @@
418416
beginEdit();
419417
}
420418

419+
// If the cellNagv module is installed and we can get the uiGridCellNavConstants value injected,
420+
// then if the column has enableCellEditOnFocus set to true, we need to listen for cellNav events
421+
// to this cell and start editing when the "focus" reaches us
421422
try {
422423
var uiGridCellNavConstants = $injector.get('uiGridCellNavConstants');
423424

@@ -512,6 +513,7 @@
512513
*
513514
*/
514515
function beginEdit() {
516+
// If we are already editing, then just skip this so we don't try editing twice...
515517
if (inEdit) {
516518
return;
517519
}

src/js/core/factories/Grid.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ angular.module('ui.grid')
12351235
*/
12361236
Grid.prototype.queueRefresh = function queueRefresh() {
12371237
var self = this;
1238+
12381239
if (self.refreshCanceller) {
12391240
$timeout.cancel(self.refreshCanceller);
12401241
}
@@ -1598,7 +1599,7 @@ angular.module('ui.grid')
15981599
*
15991600
*/
16001601
Grid.prototype.refresh = function refresh() {
1601-
// gridUtil.logDebug('grid refresh');
1602+
gridUtil.logDebug('grid refresh');
16021603

16031604
var self = this;
16041605

@@ -1664,6 +1665,11 @@ angular.module('ui.grid')
16641665
if (self.renderContainers.hasOwnProperty(containerId)) {
16651666
var container = self.renderContainers[containerId];
16661667

1668+
// Skip containers that have no canvasWidth set yet
1669+
if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
1670+
continue;
1671+
}
1672+
16671673
if (container.header) {
16681674
containerHeadersToRecalc.push(container);
16691675
}
@@ -1684,6 +1690,11 @@ angular.module('ui.grid')
16841690
for (i = 0; i < containerHeadersToRecalc.length; i++) {
16851691
container = containerHeadersToRecalc[i];
16861692

1693+
// Skip containers that have no canvasWidth set yet
1694+
if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
1695+
continue;
1696+
}
1697+
16871698
if (container.header) {
16881699
var oldHeaderHeight = container.headerHeight;
16891700
var headerHeight = gridUtil.outerElementHeight(container.header);

0 commit comments

Comments
 (0)