From a6943994a32bce6ad2c0e93d94aefd638aca5321 Mon Sep 17 00:00:00 2001 From: Dean Kerr Date: Wed, 23 Sep 2015 23:24:05 +0100 Subject: [PATCH] perf(core): prevent column set from being rebuilt each time data changes Added guard to prevent column set being rebuilt and cell templates being precompiled everytime grid data changes Fixes #4386 --- src/js/core/directives/ui-grid.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/js/core/directives/ui-grid.js b/src/js/core/directives/ui-grid.js index d6e0d5eb0e..59871a52b0 100644 --- a/src/js/core/directives/ui-grid.js +++ b/src/js/core/directives/ui-grid.js @@ -91,9 +91,12 @@ } if (newData) { + // columns length is greater than the number of row header columns, which don't count because they're created automatically + var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0); + if ( - // If we have no columns (i.e. columns length is either 0 or equal to the number of row header columns, which don't count because they're created automatically) - self.grid.columns.length === (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0) && + // If we have no columns + !hasColumns && // ... and we don't have a ui-grid-columns attribute, which would define columns for us !$attrs.uiGridColumns && // ... and we have no pre-defined columns @@ -105,8 +108,8 @@ self.grid.buildColumnDefsFromData(newData); } - // If we either have some columns defined, or some data defined - if (self.grid.options.columnDefs.length > 0 || newData.length > 0) { + // If we haven't built columns before and either have some columns defined or some data defined + if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) { // Build the column set, then pre-compile the column cell templates promises.push(self.grid.buildColumns() .then(function() {