|
60 | 60 | }
|
61 | 61 | }
|
62 | 62 |
|
63 |
| - function dataWatchFunction(n) { |
| 63 | + function dataWatchFunction(newData) { |
64 | 64 | // gridUtil.logDebug('dataWatch fired');
|
65 | 65 | var promises = [];
|
66 | 66 |
|
67 |
| - if (n) { |
68 |
| - if (self.grid.columns.length === ( self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0 ) ) { |
69 |
| - // gridUil.logDebug('loading cols in dataWatchFunction'); |
70 |
| - if (!$attrs.uiGridColumns && self.grid.options.columnDefs.length === 0) { |
71 |
| - self.grid.buildColumnDefsFromData(n); |
72 |
| - } |
| 67 | + if (newData) { |
| 68 | + if ( |
| 69 | + // 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) |
| 70 | + self.grid.columns.length === (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0) && |
| 71 | + // ... and we don't have a ui-grid-columns attribute, which would define columns for us |
| 72 | + !$attrs.uiGridColumns && |
| 73 | + // ... and we have no pre-defined columns |
| 74 | + self.grid.options.columnDefs.length === 0 && |
| 75 | + // ... but we DO have data |
| 76 | + n.length > 0 |
| 77 | + ) { |
| 78 | + // ... then build the column definitions from the data that we have |
| 79 | + self.grid.buildColumnDefsFromData(n); |
| 80 | + } |
| 81 | + |
| 82 | + // If we either have some columns defined, or some data defined |
| 83 | + if (self.grid.options.columnDefs.length > 0 || newData.length > 0) { |
| 84 | + // Build the column set, then pre-compile the column cell templates |
73 | 85 | promises.push(self.grid.buildColumns()
|
74 | 86 | .then(function() {
|
75 |
| - self.grid.preCompileCellTemplates();} |
76 |
| - )); |
| 87 | + self.grid.preCompileCellTemplates(); |
| 88 | + })); |
77 | 89 | }
|
| 90 | + |
78 | 91 | $q.all(promises).then(function() {
|
79 |
| - self.grid.modifyRows(n) |
| 92 | + self.grid.modifyRows(newData) |
80 | 93 | .then(function () {
|
81 | 94 | // if (self.viewport) {
|
82 | 95 | self.grid.redrawInPlace();
|
|
0 commit comments