Skip to content

Any event to know when to call .cellHeight() instead of waiting with setTimeout #2989

Closed
@maxkoretskyi

Description

@maxkoretskyi

If I increase the width of the gridstack container and immediately call .cellHeight() to re-compute row height, there's no effect, I need to wait a bit before calling .cellHeight():

const hostEl = document.querySelector('#grid');

const grid = GridStack.init({
    column: 12,
    cellHeight: 'initial',
    float: false,
}, hostEl);

grid.addWidget({w: 2, h: 2, content: 'item 1'});

document.querySelector('#increase-width')
.addEventListener('click', function() {
  hostEl.style.width = '1000px';

  // doesn't work
  grid.cellHeight('initial');

  // but works with timeout
  setTimeout(()=>grid.cellHeight('initial'), 300);
});

I'm wondering if there's a better approach than arbitrary timeout? Maybe there's some kind of event I can subscribe to?

Appreciate any input!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions