Grid not rendered correctly when using ng-show / ng-hide
Steps to reproduce:
- Create a grid
- Add the
ng-showdirective and tell the grid to only show when more than 0 items are available - Initialize your items with an empty array
- Fill in data to your items array at a later point in time (web service, timeout, …)
Expected result:
- The grid is initially hidden, and gets shown once the data are set.
Actual result:
- The grid is initially hidden, and stays hidden once the data are set.
Versions used:
- AngularJS 1.2.2
- ngGrid 2.0.7
Encountered the same issue. Using ng-if instead of ng-show/ng-hide seems to correct the issue.
My approach is to call GridOptions.$gridServices.DomUtilityService.RebuildGrid() explicitly to trigger a rebuild after hide to show convertion.
On Wed, Dec 4, 2013 at 11:35 PM, pmacmillan [email protected]:
Encountered the same issue. Using ng-if instead of ng-show/ng-hide seems to correct the issue.
— Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/ng-grid/issues/855#issuecomment-29814855 .
can you please give an example of how to call RebuildGrid, what specific are the two params? Thanks for any help
@j-walker23 This seems to work for me:
$scope.gridOptions.$gridServices.DomUtilityService.RebuildGrid(
$scope.gridOptions.$gridScope,
$scope.gridOptions.ngGrid
);
Yeah, it took me along time to figure that out. I didn't know about $gridScope, about an hour of chrome debugging. Thanks for the response!
Thanks @pmacmillan, ng-if fixed the problem for me.
ng-grid is not rendering the correct height of row if the parent is hidden at load using ng-show and shown on a different event triggered by user. I tried couple of solution which are working in ng-grid version prior 2.0.7 but not with 2.0.7 with angular 1.2.12.
ng-if might work as it will inject the content to the DOM and recreate the scope each time the expression is true, which is a costly operation if your content is static for an instance.
Please try and set the width of the grid using style, I was facing the same issue in which the one grid will not draw if the other one does, in multiple tabs
height of my grid is calculating correctly. when i search data and load the result in grid only top six results are visible where i get 10 result. Space for remaining results are visible in grid area but not result. Once i press F12 button to check html n console complete result get visible. i didn't understand the issue.
$scope.superClassGridOptions = {
rowHeight: 34,
multiSelect : false,
columnDefs : [
{
field : 'id',
visible : false
},
{
field : 'name',
displayName : 'Class',
width : '27%',
cellTemplate : ''
},
{
field : 'attendanceAllowed',
displayName : 'Attendance Allowed',
width : '10%',
cellTemplate : ''
},
{
field : 'subclasses',
displayName : 'Sub-Classes',
width : '52%',
cellTemplate : ''
},
{
field : 'Action',
displayName : 'Action',
cellTemplate : '',
width : '10%'
} ],
data : 'superclasses'
};
Method where i am calling Serivce for data --
$scope.searchSuperClass = function(searchString){ var strLen = searchString.length; if(strLen >2){ SuperclassService.searchSuperclasses({searchTerm: searchString}, function(response) { if(response.data === undefined){ $scope.superclasses = []; }else{ $scope.superclasses = response.data; } $scope.isAnyEditable = false; }, function(error){ console.log("Superclass is not find.... Please try again"); $scope.isAnyEditable = false; }); } };
$scope.setGridHeight = function (dataList) { var rowHeight = 34; var headerHeight = 35; if (dataList == null || dataList === undefined && dataList.length === 0) { return { height: 0 + "px" }; } else { return { height: (dataList.length * rowHeight + headerHeight) + "px" }; } };
HTML Part:
<div class="row">
<div class="col-md-12">
<div class="gridStyle" ng-grid="superClassGridOptions"
ng-style="setGridHeight(superclasses)"
style="float: left; display: inline-block;"></div>
</div>
</div>
Please help .
Thanks in advance.
Please put the gridOptions from your controller which is binding the grid
I observed the same issue as well, the view is not getting refreshed for some reason and not displaying the proper height. With another $digest the view is updating i.e. on showing web inspector or resizing the window. You can forcefully run another $digest and refresh the grid in a $timeout event after setting the data. This is just a workaround till the issue get fixed in ng-grid.
@theluckin May be it is a very easy question for other but i dont know how to refresh to grid... i know the about $timeout i didn't find it anywhere.
$timeout(function() {
$scope.gridOptions.$gridServices.DomUtilityService.RebuildGrid(
$scope.gridOptions.$gridScope,
$scope.gridOptions.ngGrid
);
}, 600);
ngIf works, but there should be solution for ngShow too.
It started working for me when i remove "width:'10%'" from last template. i don't why only the last cell definition was creating problem. But its just working fine for me.
I had a similar issue. My grid was part of a larger div that was hidden when there was no items to display. I have a button on the form that allows to add a new item. After the insertion, the grid was showing the space for the new row, but all the columns were set to a width=0.
Removing the width:5% also fixed it for me. Thanks @ Deepakmalik50, I must have searched for this problem the last 2 hours!
This issue still exists in the v2.0.14 of ngGrid.
As people above have suggested, rebuild the grid and apart for a little flicker from the grid while it rebuilds it's a suitable workaround.
Example (where isLoading is a function that determines if the grid has a load in-progress):
$scope.$watch('isLoading()', function (newVal) {
if (!newVal) {
$timeout(function () {
if ($scope.gridOptions.$gridServices) {
$scope.gridOptions.$gridServices.DomUtilityService.RebuildGrid(
$scope.gridOptions.$gridScope,
$scope.gridOptions.ngGrid);
}
});
}
}, true);
I'm having this exact same problem. Any clues?
Seems to be related to https://github.com/angular-ui/ng-grid/issues/799
same here while using different bootstrap tabs. the grid stays empty unless i resize the browser .... fixed with upgrade angular 1.4
Doesn't solve for me with angular 1.4.
The quickest option is to add 'ui-grid-auto-resize' in your dom element -
<div ui-grid="gridOptions" ui-grid-edit class="grid" ui-grid-auto-resize></div>