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

Column width issue when grid is % sized

Open willi1s opened this issue 11 years ago • 7 comments

I am using a grid which has the width set to 100%, and have some (but not all) columns sized at fixed values.

This worked fine with rc19, but with rc21 the columns widths are incorrect, each cell is sized to its contents.

This occurs because the new init function is called multiple times, this sets up grid.gridWidth based on the return value of gridUtil.elementWidth($elm). Most of the time this function is returning the width in pixels .e.g 16601 however, sometimes it is returning100%. The functiongetWidthOrHeight()` has a shortcut out if the value is not in px, and so the calling code gets confused as it performs some maths on a value of 100% resulting in NaN and so the column width gets set to NaNpx.

As a test, I changed:

grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);

to:

var w = gridUtil.elementWidth($elm);
if(angular.isNumber(w)) {
    grid.gridWidth = $scope.gridWidth = w;
}

And this did resolve the issue, however as gridUtil.elementWidth() is called in lots of places, this probably needs a more comprehensive fix.

I've been trying to reproduce this in Plnkr but with no success as yet. I'll add a plunk when I can reproduce it.

willi1s avatar May 07 '15 09:05 willi1s

I have managed to reproduce this here: http://plnkr.co/edit/LORr2MPay1cBGNt2TMV8

As you can see, I create the grid hidden, and then show it and it goes wrong :-(

The init() function first gets called from the compile.post where it has the correct size, and then again from the $timeout called from checkSize() which gives it 100% then when the grid is displayed, the size is not re-evaluated.

willi1s avatar May 07 '15 16:05 willi1s

It appears that if I wrap my code in an ng-if rather than an ng-show it works, so I guess the root cause is that the grid is created hidden. I'll try to restructure my app to work around, but there is clearly an underlying issue there

willi1s avatar May 08 '15 09:05 willi1s

Willi1s - were you able to get through this issue? I had the same issue with ng-show and I changed it to ng-if and the table columns now get the correct size, but it still does not render all the rows for me. On page resize or on sorting, I get all the rows. Did you have a similar issue?

geethaar09 avatar May 15 '15 23:05 geethaar09

Refer http://ui-grid.info/docs/#/tutorial/108_hidden_grids

PaulL1 avatar May 15 '15 23:05 PaulL1

Solution provided that may resolve it, no comment for 3 weeks, closing, please re-raise or reopen if this is still occurring.

PaulL1 avatar Jun 06 '15 01:06 PaulL1

The hidden grid solution is not applicable for when you want to have the grid fit its parent element (when you want your page to be responsive) and set the grid size (height,width) to 100% (or calculated). It seems that the checkSize method is causing the grid to mess the layout (second call to init).

joegilad avatar Apr 04 '16 09:04 joegilad

@PaulL1 the link you provided no longer works. I've tried the ngIf directive which does work, but I'd like to see what you were proposing.

jacques-hoventer avatar May 03 '18 08:05 jacques-hoventer