Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
maxkoretskyi opened this issue Mar 13, 2025 · 2 comments

Comments

@maxkoretskyi
Copy link

maxkoretskyi commented Mar 13, 2025

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!

@adumesny
Copy link
Member

use cellHeight: 'auto' and gs will track changes. also this is a DOM question. see GS code for size event

@maxkoretskyi
Copy link
Author

thanks for your response, auto doesn't work for me b/c it always tracks changes, but I need to recompute rowheight only on certain occasitions and after the recompute I need the height to stay the same.

see GS code for size event

could you maybe link to a relevant piece in sources?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants