diff --git a/src/directives/hotTable.js b/src/directives/hotTable.js index fa455421..2372f0d1 100644 --- a/src/directives/hotTable.js +++ b/src/directives/hotTable.js @@ -117,7 +117,6 @@ } else { scope.hotInstance.loadData(newValue); scope.htSettings.data = newValue; - } } else if (newValue !== oldValue) { scope.htSettings[key] = newValue; @@ -125,6 +124,19 @@ } }, ['datarows', 'columns', 'rowHeights', 'colWidths', 'rowHeaders', 'colHeaders'].indexOf(key) >= 0); }); + + /** + * Check for reference equality changes for datarows + * TODO: must the remaining bindingsKeys need to be added also if their reference changes + */ + scope.$watch('datarows', function(newValue) { + if (newValue === void 0) { + return; + } + if (scope.hotInstance.getSettings().data !== newValue) { + scope.hotInstance.loadData(newValue); + } + }); /** * Check if data length has been changed diff --git a/test/directives/hotTable/watchingOptions.spec.js b/test/directives/hotTable/watchingOptions.spec.js index 2b8f8f4e..86d9ffad 100644 --- a/test/directives/hotTable/watchingOptions.spec.js +++ b/test/directives/hotTable/watchingOptions.spec.js @@ -20,9 +20,29 @@ describe('hotTable - Watching options', function() { scope.$digest(); - expect(scope.hotInstance.getData()).toBe(rootScope.value); + expect(scope.hotInstance.getSettings().data).toBe(rootScope.value); }); + + it('should ensure a new copy of `datarows` is made when the reference is changed but it has the same value', function() { + rootScope.value = [[1,2,3,4]]; + var scope = angular.element(compile('')(rootScope)).isolateScope(); + + scope.$digest(); + + expect(scope.hotInstance.getSettings().data).toBe(rootScope.value); + + rootScope.value = [[1, 2, 3, 4]]; + rootScope.$digest(); + + expect(scope.hotInstance.getSettings().data).toBe(rootScope.value); + + rootScope.value.push([[5, 6, 7, 8]]); + scope.$digest(); + + expect(scope.hotInstance.getSettings().data).toBe(rootScope.value); + }); + it('should create table with `dataSchema` attribute', function() { rootScope.value = {id: null}; var scope = angular.element(compile('')(rootScope)).isolateScope(); @@ -831,4 +851,4 @@ describe('hotTable - Watching options', function() { expect(scope.hotInstance.getSettings().className).toBe('foo'); expect(scope.hotInstance.getSettings().data).toEqual([[1]]); }); -}); +}); \ No newline at end of file