Skip to content

Commit 205a215

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(Grid.js): Reducing amount of digests cycles triggered.
#5007
1 parent 56f0dc1 commit 205a215

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,10 @@
7171
function columnDefsWatchFunction(n, o) {
7272
if (n && n !== o) {
7373
self.grid.options.columnDefs = $scope.uiGrid.columnDefs;
74-
self.grid.buildColumns({ orderByColumnDefs: true })
75-
.then(function(){
76-
77-
self.grid.preCompileCellTemplates();
78-
79-
self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN);
80-
}).catch(angular.noop);
74+
self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, {
75+
orderByColumnDefs: true,
76+
preCompileCellTemplates: true
77+
});
8178
}
8279
}
8380

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

245242
// Setup event listeners and watchers
246243
function setup() {
247-
var deregisterLeftWatcher;
248-
var deregisterRightWatcher;
244+
var deregisterLeftWatcher, deregisterRightWatcher;
249245

250246
// Bind to window resize events
251247
angular.element($window).on('resize', gridResize);

src/js/core/factories/Grid.js

+29-23
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ angular.module('ui.grid')
595595
callback.types.indexOf( type ) !== -1 ||
596596
type === uiGridConstants.dataChange.ALL ) {
597597
if (callback._this) {
598-
callback.callback.apply(callback._this,this);
598+
callback.callback.apply(callback._this, this, options);
599599
}
600600
else {
601-
callback.callback( this );
601+
callback.callback(this, options);
602602
}
603603
}
604604
}, this);
@@ -636,10 +636,11 @@ angular.module('ui.grid')
636636
* is notified, which triggers handling of the visible flag.
637637
* This is called on uiGridConstants.dataChange.COLUMN, and is
638638
* registered as a dataChangeCallback in grid.js
639-
* @param {string} name column name
639+
* @param {object} grid The grid object.
640+
* @param {object} options Any options passed into the callback.
640641
*/
641-
Grid.prototype.columnRefreshCallback = function columnRefreshCallback( grid ){
642-
grid.buildColumns();
642+
Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options){
643+
grid.buildColumns(options);
643644
grid.queueGridRefresh();
644645
};
645646

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

765769
//default order
@@ -791,11 +795,13 @@ angular.module('ui.grid')
791795
return a.headerPriority - b.headerPriority;
792796
});
793797

794-
self.buildColumns()
795-
.then( function() {
796-
self.preCompileCellTemplates();
797-
self.queueGridRefresh();
798-
}).catch(angular.noop);
798+
if (!stopColumnBuild) {
799+
self.buildColumns()
800+
.then(function() {
801+
self.preCompileCellTemplates();
802+
self.queueGridRefresh();
803+
}).catch(angular.noop);
804+
}
799805
}).catch(angular.noop);
800806
};
801807

@@ -913,6 +919,9 @@ angular.module('ui.grid')
913919
if (self.rows.length > 0){
914920
self.assignTypes();
915921
}
922+
if (options.preCompileCellTemplates) {
923+
self.preCompileCellTemplates();
924+
}
916925
}).catch(angular.noop);
917926
};
918927

@@ -1617,12 +1626,11 @@ angular.module('ui.grid')
16171626
* @methodOf ui.grid.class:Grid
16181627
* @description calls each styleComputation function
16191628
*/
1620-
// TODO: this used to take $scope, but couldn't see that it was used
16211629
Grid.prototype.buildStyles = function buildStyles() {
1622-
// gridUtil.logDebug('buildStyles');
1623-
16241630
var self = this;
16251631

1632+
// gridUtil.logDebug('buildStyles');
1633+
16261634
self.customStyles = '';
16271635

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

2117-
if (buildStyles) {
2118-
self.buildStyles();
2119-
}
2125+
// gridUtil.logDebug('refreshCanvas');
21202126

21212127
var p = $q.defer();
21222128

@@ -2140,6 +2146,11 @@ angular.module('ui.grid')
21402146
}
21412147
}
21422148

2149+
// Build the styles without the explicit header heights
2150+
if (buildStyles) {
2151+
self.buildStyles();
2152+
}
2153+
21432154
/*
21442155
*
21452156
* Here we loop through the headers, measuring each element as well as any header "canvas" it has within it.
@@ -2153,11 +2164,6 @@ angular.module('ui.grid')
21532164
*
21542165
*/
21552166
if (containerHeadersToRecalc.length > 0) {
2156-
// Build the styles without the explicit header heights
2157-
if (buildStyles) {
2158-
self.buildStyles();
2159-
}
2160-
21612167
// Putting in a timeout as it's not calculating after the grid element is rendered and filled out
21622168
$timeout(function() {
21632169
// var oldHeaderHeight = self.grid.headerHeight;

0 commit comments

Comments
 (0)