Skip to content

Commit

Permalink
fix(Grid): Avoid too-early header height calc
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
c0bra committed Nov 13, 2014
1 parent 91bf06f commit a335b92
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/features/cellnav/js/cellnav.js
Expand Up @@ -745,8 +745,8 @@
* @restrict A
* @description Stacks on top of ui.grid.uiGridCell to provide cell navigation
*/
module.directive('uiGridCell', ['$timeout', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants',
function ($timeout, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants) {
module.directive('uiGridCell', ['$timeout', '$document', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants',
function ($timeout, $document, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants) {
return {
priority: -150, // run after default uiGridCell directive and ui.grid.edit uiGridCell
restrict: 'A',
Expand All @@ -772,7 +772,12 @@
rowCol.col === $scope.col) {
setFocused();

if (rowCol.hasOwnProperty('eventType') && rowCol.eventType === uiGridCellNavConstants.EVENT_TYPE.KEYDOWN) {
if (
// This cellNav event came from a keydown event so we can safely refocus
(rowCol.hasOwnProperty('eventType') && rowCol.eventType === uiGridCellNavConstants.EVENT_TYPE.KEYDOWN)
// The focus has gone to the body element, because we've probably wrapped around
// ($document.activeElement === $document.body)
) {
$elm.find('div')[0].focus();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/features/edit/js/gridEdit.js
Expand Up @@ -394,7 +394,6 @@
$elm.on('keydown', beginEditKeyDown);
if ($scope.col.colDef.enableCellEditOnFocus) {
$elm.find('div').on('focus', beginEditFocus);
// $elm.find('div').on('click', beginEditFocus);
}
}

Expand All @@ -403,7 +402,6 @@
$elm.off('keydown', beginEditKeyDown);
if ($scope.col.colDef.enableCellEditOnFocus) {
$elm.find('div').off('focus', beginEditFocus);
// $elm.find('div').off('click', beginEditFocus);
}
}

Expand All @@ -418,6 +416,9 @@
beginEdit();
}

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

Expand Down Expand Up @@ -512,6 +513,7 @@
*
*/
function beginEdit() {
// If we are already editing, then just skip this so we don't try editing twice...
if (inEdit) {
return;
}
Expand Down
13 changes: 12 additions & 1 deletion src/js/core/factories/Grid.js
Expand Up @@ -1235,6 +1235,7 @@ angular.module('ui.grid')
*/
Grid.prototype.queueRefresh = function queueRefresh() {
var self = this;

if (self.refreshCanceller) {
$timeout.cancel(self.refreshCanceller);
}
Expand Down Expand Up @@ -1598,7 +1599,7 @@ angular.module('ui.grid')
*
*/
Grid.prototype.refresh = function refresh() {
// gridUtil.logDebug('grid refresh');
gridUtil.logDebug('grid refresh');

var self = this;

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

// Skip containers that have no canvasWidth set yet
if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
continue;
}

if (container.header) {
containerHeadersToRecalc.push(container);
}
Expand All @@ -1684,6 +1690,11 @@ angular.module('ui.grid')
for (i = 0; i < containerHeadersToRecalc.length; i++) {
container = containerHeadersToRecalc[i];

// Skip containers that have no canvasWidth set yet
if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
continue;
}

if (container.header) {
var oldHeaderHeight = container.headerHeight;
var headerHeight = gridUtil.outerElementHeight(container.header);
Expand Down

0 comments on commit a335b92

Please sign in to comment.