You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I remember I seen this bug as well at some point when I was playing with gridstack and media queries.
just throwing a question to maybe help narrow the issue: do you have a custom number of columns?
please post a bug with a simple jsfidle running jsfidle or similar example as the template requires... do't expect me to crete one for you, then fix any issues...
Also, you'll notice that i do dynamic import
const { GridStack } = await import('gridstack')
in my local project, it throws me an error during serverside rendering if i import like
import {GridStack} from 'gridstack'
will have to dup this in a simple js example. you are destroying and recreating the grid, which is odd. makeWidget() or load() is what you should call instead...
As you can notice first 2 items (1 and 2) have x and y attributes but last one (3) does not have x and y. So I expected last item to appear on right after 2. But something weird happens and 3 appears between 1 and 2.
this.getGridItems().forEach(el=>{// get dom elements (not nodes yet)letx=parseInt(el.getAttribute('gs-x'));lety=parseInt(el.getAttribute('gs-y'));elements.push({
el,// if x,y are missing (autoPosition) add them to end of list - but keep their respective DOM orderi: (Number.isNaN(x) ? 1000 : x)+(Number.isNaN(y) ? 1000 : y)*column});});elements.sort((a,b)=>b.i-a.i).forEach(e=>this._prepareElement(e.el));// revert sort so lowest item wins
So elements from example are eq to
this._prepareElement calls this.engine.addNode -> this.engine.findEmptyPosition is called only for item 3 and is called before first 2 items are added to engine.nodes.
not sure why i reverse sorted items - lcearly autoPosition need to be done in the DOM order. the only question is if you have 2 widgets with specific conflicting position, which one wins ? could go either way, so dom order palcement is likely more natural and last one wins.
will have to dup this in a simple js example. you are destroying and recreating the grid, which is odd. makeWidget() or load() is what you should call instead...
Oh, i believe it is due to Gridstack not being able to detect vue 3's reactive v-for changes.
Here's a link of an issue about it. #2076
Thank you for providing a better example @ildarkayumov
fixed in next release - this turned out to be more work than I expected as I need to make sure loading into 1 or 12 column acted the same, and bunch of new stuff needed to happen.
don't forget to donate if you find this lib useful!
Activity
fredericrous commentedon Mar 17, 2023
I remember I seen this bug as well at some point when I was playing with gridstack and media queries.
just throwing a question to maybe help narrow the issue: do you have a custom number of columns?
stephenjason89 commentedon Mar 17, 2023
@fredericrous hello thanks for looking in to this.
No I don't,
I only have these in my gridOptions
adumesny commentedon Mar 17, 2023
please post a bug with a simple jsfidle running jsfidle or similar example as the template requires... do't expect me to crete one for you, then fix any issues...
stephenjason89 commentedon Mar 23, 2023
@adumesny sorry about that.

Here's a stackblitz
https://stackblitz.com/edit/nuxt-starter-weppuk?file=app.vue
Press the add button and you'll see this is happening.
Downgrade to 6.0.3 to see the correct behavior.

Also, you'll notice that i do dynamic import
const { GridStack } = await import('gridstack')
in my local project, it throws me an error during serverside rendering if i import like
import {GridStack} from 'gridstack'
Thank you so much
adumesny commentedon Mar 23, 2023
will have to dup this in a simple js example. you are destroying and recreating the grid, which is odd. makeWidget() or load() is what you should call instead...
ildarkayumov commentedon Mar 24, 2023
Hello
I had the same issue - https://jsfiddle.net/ildarkayumov/05Lthmpx/
As you can notice first 2 items (
1and2) havexandyattributes but last one (3) does not havexandy. So I expected last item to appear on right after2. But something weird happens and3appears between1and2.I investigated the problem a little bit and found that it started after these changes https://github.com/gridstack/gridstack.js/blob/master/src/gridstack.ts#L361
So elements from example are eq to
this._prepareElementcallsthis.engine.addNode->this.engine.findEmptyPositionis called only for item3and is called before first 2 items are added to engine.nodes.I resolved the problem with small 'hack' like here - https://jsfiddle.net/ildarkayumov/ruzc9g3x/
I added
gs-y="-1000"to last elementthat allows to make calculated
ifor last elemet to be eq1000 + -1000 * 12 = -10000adumesny commentedon Mar 25, 2023
thank you @ildarkayumov that example makes it easy to debug and fix now https://jsfiddle.net/adumesny/yt4ghjdn/
not sure why i reverse sorted items - lcearly autoPosition need to be done in the DOM order. the only question is if you have 2 widgets with specific conflicting position, which one wins ? could go either way, so dom order palcement is likely more natural and last one wins.
stephenjason89 commentedon Mar 26, 2023
Oh, i believe it is due to Gridstack not being able to detect vue 3's reactive v-for changes.
Here's a link of an issue about it. #2076
Thank you for providing a better example @ildarkayumov
fix autoPlacement from DOM reading
adumesny commentedon Mar 26, 2023
fixed in next release - this turned out to be more work than I expected as I need to make sure loading into 1 or 12 column acted the same, and bunch of new stuff needed to happen.
don't forget to donate if you find this lib useful!
stephenjason89 commentedon Mar 26, 2023
Thank you @adumesny
Will do.
test partial fix