ErickRuano / angular-pivot

Angular wrapper for Nicolas Kruchten's Pivot Table
MIT License
15 stars 13 forks source link

No data #5

Closed mattys31 closed 6 years ago

mattys31 commented 7 years ago

Hi,

Firstly, this is great.

Secondly, I'm not exactly a master at this stuff so there's plenty of potential for this being a simple error on my side....

But..

when I extract data using a callback I can't get data into the pivot table.

I created a simple table with ng-repeat to render the rows so I can verify that my $scope.data array has data in it, but it seems the pivot chart doesn't get notified of the changes to the array.

So the controller contains

$scope.data = []; $scope.options = { rows: [], cols: [] };

      ***Data retrieval function ***.then(function (reply) {
            console.log("found " + reply.rows + " rows"); // always returns rows 
            angular.copy(reply.rows,$scope.data);
            console.log($scope.data) // contains the rows from the reply
        }, function (failure) {
            console.log("Failed to get %o", failure)
        });

As I say, a simple HTML table renders the rows of $scope.data but the pivot chart doesn't.

Many thanks

Matt

ErickRuano commented 6 years ago

I'm really sorry for my late response.

Probably your callback code is not part of AngularJS environment so although you update the value of $scope.data you will need to call a $scope.$apply() for it to work as expected.

More info here http://jimhoskins.com/2012/12/17/angularjs-and-apply.html