I am using angularjs 1.5.0 with angular ui grid 3.1.1. When I assign gridOptions (passed to the grid directive) object in controller body like this:
$scope.gridOptions = {
data: [{"mock2": 1, "mock1": 2}, {"mock2": 10, "mock1": 22} ]
};
HTML:
<div ui-grid="gridOptions"></div>
It displays the table as expected. But when I try to change data inside $scope.on:
$scope.$on('update', function (event, passedFromBroadcast) {
$scope.gridOptions.data= [{"mock2": "set", "mock1": "inside"}, {"mock2": "$scope", "mock1": "on"} ] ;
});
It renders only frame of the table, when including pagination it will also render pagination related controls - but not the content itself. Content (the rows and column headers) appear only after I resize my browser window.
How can I manually update the angular ui grid table? Things I already tried:
$scope.gridApi.core.handleWindowResize(); // Does not work
$scope.gridApi.core.refresh(); // Does not work
$timeout(function(){$scope.gridOptions.data= [{"mock2": "set", "mock1": "inside"}, {"mock2": "$scope", "mock1": "on"} ] ;}) // Does not work
It's a known bug when the gridOptions.data length doesn't change after update, proposed solution is to clear data and with use of $timeout refresh it
$scope.$on('update', function (event, passedFromBroadcast) {
$scope.gridOptions.data = null
$timeout(function(){
$scope.gridOptions.data = [{"mock2": "set", "mock1": "inside"}, {"mock2": "$scope", "mock1": "on"} ] ;
});
});
There are a two issues with this code, but the reason for the table contents showing only after browser window resize is lack of css class defining width and height, basic (working) example:
.grid {
width: 500px;
height: 250px;
}
and in HTML:
<div class="grid" ui-grid="gridOptions"></div>
The Other issue (mentioned by other people in this thread:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With