Golden-layout: Golden Layout not resizing with browser screen when inside DIV. Prevent hard-coded height and width in my container?

Created on 31 Jul 2018  路  3Comments  路  Source: golden-layout/golden-layout

When I use:
myLayout = new window.GoldenLayout(config, $('#mydiv'));

to attach my configured layout to a container DIV, the content generated by Golden Layout doesn't resize automatically when I expand/contract my browser. It does so when I just do:
myLayout = new window.GoldenLayout(config);

and write the layout to my body tag.

When I inspect the code that Golden Layout inserts into my DIV, I see that all of the sub-elements have hardcoded style tags attached that set the width and height attributes to hard-coded values.

When I re-size the screen, my Golden Layout windows stay the same size.

Does anyone know how to make it so the GL will auto-size to the size of my browser window?

Most helpful comment

Thanks again for your help, Malled!

Here is the exact code that works for me. I hope it helps someone else:

$(window).resize(function () {
myLayout.updateSize($(window).width(), $(window).height());
});

All 3 comments

You have to bind your own resize handler on browser resize event and call updateSize(...) method.
Use plain JS
window.addEventListener('resize', function(event){ // do stuff here });
(source https://stackoverflow.com/questions/641857/javascript-window-resize-event)
or jquery https://api.jquery.com/resize/

Thanks again for your help, Malled!

Here is the exact code that works for me. I hope it helps someone else:

$(window).resize(function () {
myLayout.updateSize($(window).width(), $(window).height());
});

Updating layout size on state changed worked for me. This also resolved resizing issues when clicking on tabs or adjusting boundaries
let width = $(window).width(); let height = $(window).height(); myLayout.on( 'stateChanged', () => myLayout.updateSize(width, height));

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raptoria picture raptoria  路  8Comments

ldetomi picture ldetomi  路  5Comments

gigamorph picture gigamorph  路  3Comments

ButchMonkey picture ButchMonkey  路  4Comments

pmunin picture pmunin  路  8Comments