Skip to content

Commit

Permalink
fix(Grid.js): Reducing amount of digests cycles triggered.
Browse files Browse the repository at this point in the history
  • Loading branch information
Portugal, Marcelo authored and mportuga committed Mar 24, 2017
1 parent 56f0dc1 commit 205a215
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
14 changes: 5 additions & 9 deletions src/js/core/directives/ui-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@
function columnDefsWatchFunction(n, o) {
if (n && n !== o) {
self.grid.options.columnDefs = $scope.uiGrid.columnDefs;
self.grid.buildColumns({ orderByColumnDefs: true })
.then(function(){

self.grid.preCompileCellTemplates();

self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN);
}).catch(angular.noop);
self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, {
orderByColumnDefs: true,
preCompileCellTemplates: true
});
}
}

Expand Down Expand Up @@ -244,8 +241,7 @@ function uiGridDirective($window, gridUtil, uiGridConstants) {

// Setup event listeners and watchers
function setup() {
var deregisterLeftWatcher;
var deregisterRightWatcher;
var deregisterLeftWatcher, deregisterRightWatcher;

// Bind to window resize events
angular.element($window).on('resize', gridResize);
Expand Down
52 changes: 29 additions & 23 deletions src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,10 @@ angular.module('ui.grid')
callback.types.indexOf( type ) !== -1 ||
type === uiGridConstants.dataChange.ALL ) {
if (callback._this) {
callback.callback.apply(callback._this,this);
callback.callback.apply(callback._this, this, options);
}
else {
callback.callback( this );
callback.callback(this, options);
}
}
}, this);
Expand Down Expand Up @@ -636,10 +636,11 @@ angular.module('ui.grid')
* is notified, which triggers handling of the visible flag.
* This is called on uiGridConstants.dataChange.COLUMN, and is
* registered as a dataChangeCallback in grid.js
* @param {string} name column name
* @param {object} grid The grid object.
* @param {object} options Any options passed into the callback.
*/
Grid.prototype.columnRefreshCallback = function columnRefreshCallback( grid ){
grid.buildColumns();
Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options){
grid.buildColumns(options);
grid.queueGridRefresh();
};

Expand Down Expand Up @@ -757,9 +758,12 @@ angular.module('ui.grid')
* @name addRowHeaderColumn
* @methodOf ui.grid.class:Grid
* @description adds a row header column to the grid
* @param {object} column def
* @param {object} colDef Column definition object.
* @param {float} order Number that indicates where the column should be placed in the grid.
* @param {boolean} stopColumnBuild Prevents the buildColumn callback from being triggered. This is useful to improve
* performance of the grid during initial load.
*/
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order) {
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order, stopColumnBuild) {
var self = this;

//default order
Expand Down Expand Up @@ -791,11 +795,13 @@ angular.module('ui.grid')
return a.headerPriority - b.headerPriority;
});

self.buildColumns()
.then( function() {
self.preCompileCellTemplates();
self.queueGridRefresh();
}).catch(angular.noop);
if (!stopColumnBuild) {
self.buildColumns()
.then(function() {
self.preCompileCellTemplates();
self.queueGridRefresh();
}).catch(angular.noop);
}
}).catch(angular.noop);
};

Expand Down Expand Up @@ -913,6 +919,9 @@ angular.module('ui.grid')
if (self.rows.length > 0){
self.assignTypes();
}
if (options.preCompileCellTemplates) {
self.preCompileCellTemplates();
}
}).catch(angular.noop);
};

Expand Down Expand Up @@ -1617,12 +1626,11 @@ angular.module('ui.grid')
* @methodOf ui.grid.class:Grid
* @description calls each styleComputation function
*/
// TODO: this used to take $scope, but couldn't see that it was used
Grid.prototype.buildStyles = function buildStyles() {
// gridUtil.logDebug('buildStyles');

var self = this;

// gridUtil.logDebug('buildStyles');

self.customStyles = '';

self.styleComputations
Expand Down Expand Up @@ -2114,9 +2122,7 @@ angular.module('ui.grid')
Grid.prototype.refreshCanvas = function(buildStyles) {
var self = this;

if (buildStyles) {
self.buildStyles();
}
// gridUtil.logDebug('refreshCanvas');

var p = $q.defer();

Expand All @@ -2140,6 +2146,11 @@ angular.module('ui.grid')
}
}

// Build the styles without the explicit header heights
if (buildStyles) {
self.buildStyles();
}

/*
*
* Here we loop through the headers, measuring each element as well as any header "canvas" it has within it.
Expand All @@ -2153,11 +2164,6 @@ angular.module('ui.grid')
*
*/
if (containerHeadersToRecalc.length > 0) {
// Build the styles without the explicit header heights
if (buildStyles) {
self.buildStyles();
}

// Putting in a timeout as it's not calculating after the grid element is rendered and filled out
$timeout(function() {
// var oldHeaderHeight = self.grid.headerHeight;
Expand Down

0 comments on commit 205a215

Please sign in to comment.