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

addWidget() or DOM read in single column mode will not adjust to multicolumn mode #1985

Closed
ericpool opened this issue Jun 23, 2022 · 8 comments · Fixed by #2088
Closed

addWidget() or DOM read in single column mode will not adjust to multicolumn mode #1985

ericpool opened this issue Jun 23, 2022 · 8 comments · Fixed by #2088
Labels

Comments

@ericpool
Copy link

When a grid is loaded for the first time in single column mode instead of multicolumn mode, it will remain a single column when resizing to multicolumn mode. Multicolumn mode toggles on, but all the items remain in their left-aligned positions.

Using gridstack 4.6.2, but since it is happening in the demo too, doubt it is relevant.

You can see this happening in the demo page here:
https://gridstackjs.com/demo/nested_advanced.html

Just load the page with the browser at a small enough size to trigger single column mode, then adjust window size.

@adumesny
Copy link
Member

Only a problem with nested grids, regular ones work (as I recall fixing that issue a while back) https://gridstackjs.com/demo/web1.html

@adumesny adumesny changed the title Grid loaded in single column mode will not adjust to multicolumn mode. Nested Grids loaded in single column mode will not adjust to multicolumn mode. Jun 23, 2022
@ericpool
Copy link
Author

ericpool commented Jun 23, 2022

Only a problem with nested grids, regular ones work (as I recall fixing that issue a while back) https://gridstackjs.com/demo/web1.html

Do you recall when this issue was resolved (i.e. maybe I should update?)? I am having this issue while not using nested grids.

Bit of a sloppy example, but it shows how the grid will appear differently when loaded in single column mode with these settings:
https://jsfiddle.net/ericpool/7k2jya48/

@adumesny
Copy link
Member

no, but simple search would find related fixes... then you can see which release came after
https://github.com/gridstack/gridstack.js/issues?q=is%3Aissue+is%3Aclosed+oneColumn

@ericpool
Copy link
Author

I looked through those and they seem to address similar issues that I am having, however, it does not appear to be working as intended for me.

Here is a very plain example of the issue I am having: https://jsfiddle.net/ericpool/7k2jya48/6/

As you can see, when initializing it in single column mode, it forgets all positioning:

ezgif-3-5e4a17e604

@adumesny
Copy link
Member

ok, see the issue with simpler https://jsfiddle.net/adumesny/2r3tjnds/
adding 1 item at a time doesn't work, while load() does...

@adumesny adumesny changed the title Nested Grids loaded in single column mode will not adjust to multicolumn mode. addWidget() in single column mode will not adjust to multicolumn mode Jun 23, 2022
@decelis
Copy link

decelis commented Sep 9, 2022

Any workarounds for this issue? The same thing happens if you declare the grid items in the DOM:
https://jsfiddle.net/oqasp04y/1/

@adumesny
Copy link
Member

adumesny commented Sep 9, 2022

don't know of a workaround unless you patch the code, or add the items while in 12 columns, then go back to 1.

But you are welcome to submit a fix, or donate to get it fixed...

also your example decelis shows 2 issues - the order and the restore back to 12 (this bug), sight.

@PPP01
Copy link

PPP01 commented Sep 14, 2022

@decelis
You can use a MutationObserver as a workaround:
https://jsfiddle.net/4n93fzwr/

@adumesny adumesny changed the title addWidget() in single column mode will not adjust to multicolumn mode addWidget() or DOM read in single column mode will not adjust to multicolumn mode Oct 22, 2022
adumesny added a commit to adumesny/gridstack.js that referenced this issue Oct 23, 2022
fix gridstack#1985
fix gridstack#1975 (oneColumnModeDomSort case)

* we now handle DOM and addWidget() when temporally into 1 column mode better to save the full 12 column mode
* also DOM reading will reverse-sort entries to lay them in 1 column mode correctly (like if you had started with 12 and scaled down)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants