ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Grid not rendered correctly when using ng-show / ng-hide

Open goloroden opened this issue 13 years ago • 30 comments

Steps to reproduce:

  • Create a grid
  • Add the ng-show directive 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

goloroden avatar Nov 28 '13 08:11 goloroden

Encountered the same issue. Using ng-if instead of ng-show/ng-hide seems to correct the issue.

pmacmillan avatar Dec 04 '13 15:12 pmacmillan

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 .

JiaxiJin avatar Dec 06 '13 02:12 JiaxiJin

can you please give an example of how to call RebuildGrid, what specific are the two params? Thanks for any help

j-walker23 avatar Dec 14 '13 03:12 j-walker23

@j-walker23 This seems to work for me:

$scope.gridOptions.$gridServices.DomUtilityService.RebuildGrid(
    $scope.gridOptions.$gridScope, 
    $scope.gridOptions.ngGrid
);

nathanic avatar Dec 19 '13 15:12 nathanic

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!

j-walker23 avatar Dec 19 '13 16:12 j-walker23

Thanks @pmacmillan, ng-if fixed the problem for me.

calebmadrigal avatar Jan 13 '14 20:01 calebmadrigal

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.

theluckin avatar Mar 07 '14 07:03 theluckin

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

viveksi avatar May 02 '14 12:05 viveksi

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.

Deepakmalik50 avatar Jun 26 '14 06:06 Deepakmalik50

Please put the gridOptions from your controller which is binding the grid

viveksi avatar Jun 26 '14 07:06 viveksi

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 avatar Jun 26 '14 07:06 theluckin

@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.

Deepakmalik50 avatar Jun 26 '14 09:06 Deepakmalik50

$timeout(function() {
    $scope.gridOptions.$gridServices.DomUtilityService.RebuildGrid(
    $scope.gridOptions.$gridScope, 
    $scope.gridOptions.ngGrid
    );
}, 600);

theluckin avatar Jun 26 '14 17:06 theluckin

ngIf works, but there should be solution for ngShow too.

vs4vijay avatar Aug 08 '14 07:08 vs4vijay

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.

Deepakmalik50 avatar Aug 08 '14 09:08 Deepakmalik50

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!

ghost avatar Aug 29 '14 00:08 ghost

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);

vanslly avatar Apr 20 '15 02:04 vanslly

I'm having this exact same problem. Any clues?

Seems to be related to https://github.com/angular-ui/ng-grid/issues/799

pankas87 avatar Apr 20 '15 15:04 pankas87

same here while using different bootstrap tabs. the grid stays empty unless i resize the browser .... fixed with upgrade angular 1.4

yeahoffline avatar Aug 17 '15 14:08 yeahoffline

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>

ankittharwani avatar Oct 11 '15 23:10 ankittharwani