gdepourtales / ng-cells

AngularJS Table directive that draws a table of data with different features
http://gdepourtales.github.io/ng-cells/
Other
77 stars 17 forks source link

Updating cell data from async event #24

Closed initzero closed 9 years ago

initzero commented 9 years ago

I've noticed that if I update my data array after the grid is rendered, the changes are not reflected in the grid.

I was able to find a way to fix this by adding a third argument to the $scope.$watch() call in ng-cells.js (line 1064).

                    scope.$watch(
                        'data',
                        function(newValue, oldValue) {
                            if (newValue !== oldValue ) {
                                scope.$$updateScrollPositions(oldValue);

                                // Update the data
                                scope.$$updateData();

                                // Refresh scrollbars
                                scope.$$refreshScrollbars();

                            }
                        }, true // add true here to watch value change
                    );

Ref: http://stackoverflow.com/a/17795221/4296434

kayhadrin commented 9 years ago

Hi @initzero,

Could you provide more information about how you update the data array for ng-cells? I'm assuming that you are modifying values in the array instead of providing a new array - which would indeed make the default $watch() miss this change.

On 19 December 2014 at 05:36, initzero notifications@github.com wrote:

I've noticed that if I update my data array after the grid is rendered, the changes are not reflected in the grid.

I was able to find a way to fix this by adding a third argument to the $scope.$watch() call in ng-cells.js (line 1064).

                scope.$watch(
                    'data',
                    function(newValue, oldValue) {
                        if (newValue !== oldValue ) {
                            scope.$$updateScrollPositions(oldValue);

                            // Update the data
                            scope.$$updateData();

                            // Refresh scrollbars
                            scope.$$refreshScrollbars();

                        }
                    }, true // add true here to watch value change
                );

Ref: http://stackoverflow.com/a/17795221/4296434

— Reply to this email directly or view it on GitHub https://github.com/gdepourtales/ng-cells/issues/24.

initzero commented 9 years ago

I'm assuming that you are modifying values in the array instead of providing a new array - which would indeed make the default $watch() miss this change.

Ah yes. I am modifying the array instead of replacing it with a new one. I see the distinction now. Thanks.

kayhadrin commented 9 years ago

No worries. :-)