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

grid visual artifact within modal when width is 100%

Open longshot5112 opened this issue 11 years ago • 11 comments

I have a modal which contains a grid which should be 100% of the modal width. Upon initial loading of the modal, there is a visual artifact of the grid beyond the boundary of my modal. If I re-size my browser window, the artifact will disappear and the grid will "snap" in place where it should be and start obeying the 100% width boundary of my modal window.

This only seems to happen when loading a grid in a modal. My primary grid on the main page is set to width: 100% and has no issue.

Initial load: image

After resizing: image

This is the CSS I have for the grid: image

longshot5112 avatar Feb 03 '15 16:02 longshot5112

Hey actually this issue is part of ui-view-port directive, as a part of workaround replace ui-grid div with following code. <div ui-grid="gridOpt" class="grid" style="width:85%" ng-style="getTableStyle()" <div> Use following code on your controller. $scope.getTableStyle= function() {
return { width: "100%", height:"100%"
}; };

ghost avatar Feb 04 '15 09:02 ghost

I got the same issue. And @lifinanalytics, your workaround doesn't work for me. If the parent container's width has been set by %, Grid cannot get the correct width of parent container's width. When resizing occurs, because of parent container won't be rendered again, Grid can get correct width. Any other solution or ETA? Thanks.

tony0918 avatar Feb 05 '15 08:02 tony0918

Do this after setting data, as a workaround.

window.dispatchEvent(new Event('resize'));

httpete avatar Feb 05 '15 19:02 httpete

@tony0918 it worked very well for me ,actually was facing issue on displaying ui-grid under angular ui-tabs where i was reloading the grid data on some ui events but on every time the data refresh happens grid used to go out of the container specified, after this fix and it works well even on window resize. So coming to your issue with % size it is required to have parent width set before child can render , So there is no way you can render the table without setting parent width and height. All i suggest you to work on your source code somehow to render the parent before rendering ui-grid.

@httpete your solution is not consistent , even though you trigger resize event in some cases it doesn't work like mine in where am displaying grid in multiple tabs where ui-grid resize event won't get triggered due out of view port.

ghost avatar Feb 06 '15 12:02 ghost

Thanks @lifinanalytics. Could you please share me some code to manage the rendering order?

tony0918 avatar Feb 07 '15 15:02 tony0918

        /* This is the grid hack to fix the bad layout in all browsers */
        setTimeout(function(){
            var evt = document.createEvent('UIEvents');
            evt.initUIEvent('resize', true, false,window,0);
            window.dispatchEvent(evt);
        }, 100);

httpete avatar Feb 10 '15 16:02 httpete

If someone could throw together a quick plunker for this that would make it a lot easier to provide a fix.

c0bra avatar Feb 16 '15 21:02 c0bra

OK I made a plunker: http://plnkr.co/edit/PLqG0GeD1iAredRARp8K?p=preview

c0bra avatar Mar 30 '15 21:03 c0bra

The problem here is that for determining the grid width, gridUtil is detecting that when the grid is initialized, it has an offsetWidth of 0, so it creates a "fake" (cloned) element that it attaches to the document with visibility: hidden in order to measure it.

This causes a problem because with width: 100% when attached to the document body the grid will just fill up the whole space. THEN when the real grid is in the modal it takes up way more space than it should.

The "detached/hidden element" measurement probably needs to be adjusted to account for this case.

c0bra avatar Mar 31 '15 23:03 c0bra

@longshot5112, et al. Can you try again with latest unstable?

c0bra avatar Apr 13 '15 20:04 c0bra

No further comment for over a month, solution provided that probably resolves the issue. Closing, please re-raise if there is a reliable recreate or more information.

PaulL1 avatar May 16 '15 06:05 PaulL1