Skip to content
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

Resizing from a small screen to a larger screen doesn't set correct widget dimension when rescaled #1471

Closed
nissim-dev opened this issue Nov 19, 2020 · 8 comments
Labels

Comments

@nissim-dev
Copy link

nissim-dev commented Nov 19, 2020

Subject of the issue

Resizing from a small screen to a larger screen doesn't set correct widget dimension when rescaled

Your environment

Whatever is live on https://gridstackjs.com/ ( I think it's 2.1.0 )
Google Chrome Version 86.0.4240.198 (Official Build) (64-bit)

Steps to reproduce

Gridstack demo itself can be used to replicate the behaviour
https://gridstackjs.com/

  1. Resize your window to something smaller than 848px
  2. Open https://gridstackjs.com/. Scroll down to the grid. The grid should be in one column mode.
  3. Start increasing the size of the window by dragging it, after it becomes larger than 848px, the grid should go into "grid" mode from "onecolumn" mode
    12 columns appear but all the widgets stay on the first column.

Expected behaviour

The widgets dimension and position should be reset correctly.

Actual behaviour

Widgets stay on the first column itself and doesn't put itself in the correct position.

Here's a GIF of the behaviour

2020-11-19-16-55-43

Expected result after resizing
image

@adumesny
Copy link
Member

yeah, I'm not surprised as the 12 column layout never get saved as you load directly into 1 column layout, and we don't detect that case. Behavior might have changed with the call to load() instead of html tags being there in the dom.

@nissim-dev
Copy link
Author

Since you said "12 column layout never get saved as you load directly into 1 column layout" .

If we could initially save the 12 column layout, before loading the 1 column layout, i think that would work because, There is no problem if initially the grid is loaded onto 12 column layout, then downsized to 1 column layout and back to 12 column layout. It works perfectly fine then.

Here's a GIF
2020-11-20-09-39-29

@nissim-dev
Copy link
Author

nissim-dev commented Nov 27, 2020

I'm trying to contribute by fixing this issue, I will keep you updated

@adumesny
Copy link
Member

adumesny commented Nov 27, 2020

great, else I can take a look later. I think we just need to detect when we start with 1 column due to grid width that we had originally been 12 columns (or whatever pref column we receive) and when load() is called (which is later) remember that and treat it as 12 column layout (to be cached) before forcing it to 1 column - could check that given layout has x or width > 1 and therefore not fit to 1 column.

I'll be curious if the same broken behavior happens if you had data-gs-x=1 dom properties when loading vs load() call

@nissim-dev
Copy link
Author

Yes, I tried to do exactly something like you said, it's in prepareNode() that the width is adjusted for 1 column mode. The position/dimensions are cached in engine.layouts on engine.updateNodeWidths()

I tried to to cache the original dimensions and position in prepareNode() to engine._layouts but prepareNode is run multiple times before actual addition of node so it's no use putting it there. I cannot cache the position/dimensions on addNode() because there is no node._id generated there. _id is required for caching on engine._id

I'm in a bit of a pickle here. Maybe you can give me some ideas here, as you probably understand the data flow and logic better.

@adumesny
Copy link
Member

thanks. I'll take a look...

@adumesny
Copy link
Member

adumesny commented Nov 28, 2020

fixed in next release!
was a lot more work than I expected.... don't forget to donate $ if you find this lib useful. thanks.

adumesny added a commit to adumesny/gridstack.js that referenced this issue Nov 28, 2020
more for gridstack#1471
* make sure we load() from last to first so any collision match 12 -> 1
@nissim-dev
Copy link
Author

Thanks a lot @adumesny!, this will help a lot of devs using gridstack :)

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

No branches or pull requests

2 participants