I am trying to implement UI-grid into my app. Everything works fine when I assign static data to gridOptions.data
; however, when I assign the data to gridOptions.data
dynamically after loading the data from the server, I always get an empty string. I tried replicating the dynamic behaviour using $timeout
function as below, and the result is still the same: empty grid.
//ctrl begins
This works.
$scope.data = [
{ addedBy :"user", displayName:"Name1" },
{ addedBy :"user2", displayName:"Name2" },
{ addedBy :"user3", displayName:"Name3" }
];
This does not; leaving grid empty.
$timeout(function () {
$scope.data = [
{ addedBy :"user", displayName:"Name1" },
{ addedBy :"user2", displayName:"Name2" },
{ addedBy :"user3", displayName:"Name3" }
];
});
The rest of the code remains the same.
$scope.columnDefs = [
{name: 'displayName'},
{name: 'addedBy'}
];
$scope.gridOptions = {
columnDefs: $scope.columnDefs,
data: $scope.data
};
//ctrl ends
//html begins
<div class="col-md-12 no-padding" ui-grid="gridOptions" class="grid"></div>
//html ends
I am pretty the ui-grid should be capable to update the data when data variable changes; so is there something basic that I am missing here?