-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Resizing window causes grid items to be positioned out of order #1975
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
Comments
I enabled compact mode which sort of solves the issue, except when changing the screen size back the order of the items is different than it originally was. It seems that it starts as: It should be 1, 2, 3, 4 or |
can you post a running example (use bug template). thanks. |
Here is a sample of my code on JS Fiddle. You'll notice that as you resize the pane where the grid is that the numbers get out of order. Also, on page load, tile 9 shows up before tile 8. JSFiddle |
you need to reduce your example to just like the demos (init the grid with gs-x/gs-y values as html template, or load() with correct json) and not some convoluted template if you want me to take a look... for one thing you have Also, resizing the window will NOT in your case reflow the items as you and only you know that you have a 0-9 order list of items that fill the space. I suppose it would need a custom |
Unfortunately I can't save the X and Y position in the database because the X and Y position is different depending on the screen size which controls the number of columns shown (1 on mobile, 2 on tablet, 3 on small desktop, 4 on large desktop). I did create a function called update positions that might be helpful. It loops through a presorted array of objects and finds the next available position that the item will fit in. I run this on page load and any time the screen or layout div changes size. An issue my code has at the moment is that if someone stacks two 1h tiles next to a 2h tile it doesn't preserve that stack. I am OK with preventing stacking if that is a setting somewhere. Here is my helper function:
|
| I did create a function called update positions that might be helpful. It loops through a presorted array of objects and finds the next available position that the item will fit in. that sounds like the I'll be closing this without a simple example of what you need showing either a bug or a feature request (with corresponding donations to make it happen)... |
This is actually different from compact(). I tried that one but it caused all of the tiles to be rearranged in an arbitrary order. This preserves the tiles in the original order. |
ok, true it tries to fill any empty spot (hence the name) - could be an optional arg to keep order the same, or a different method altogether. |
could be related, but there's a bug in the code for sorting where it says in // finally re-layout them in reverse order (to get correct placement)
newNodes = utils_1.Utils.sort(newNodes, -1, column); should be instead, so that // finally re-layout them in reverse order (to get correct placement)
if (!domOrder) newNodes = utils_1.Utils.sort(newNodes, -1, column); |
Responding to the above comment:
I am experiencing a similar bug related to However, sorting works as expected if the grid is initialized on a large screen (not using oneColumnMode) and then resized so that oneColumnMode kicks in. I know this is departing perhaps from the original bug, but wanted to get a reply in here as the above comment seemed appropriate. |
fixing @doktordirk and @jjdinho bug above in next release, closing the remaining issue as not explicit about what needs to be long and too convoluted. @harrington101 if you need this fixed file a very simple separate bug again |
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)
Subject of the issue
Resizing window causes grid items to be positioned to the right. And order changes when resizing.
Your environment
Steps to reproduce
I have 4 items that are 1 column wide followed by 2 items that are 4 columns wide. With the following settings, and the window set to less than 992px, there are 2 columns but the last 2 items that were in the first row on a large screen (when there were 4 columns) are now stacked in the right column under the first 2 items like so:
1 2
_ 3
_ 4
5
6
Expected behavior
The last 2 items in the first row should flow under the first 2 items like so:
1 2
3 4
5
6
Actual behavior
Instead they flow leaving 2 blank spaces on the left like so:
1 2
_ 3
_ 4
5
6
The text was updated successfully, but these errors were encountered: