ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.03k stars 1.2k forks source link

Gridster moves certain widgets when it initializes... #335

Open BarryatVendorpages opened 10 years ago

BarryatVendorpages commented 10 years ago

After saving a group of widgets into a database and then retrieving the said group of widgets, I initialize Gridster. Certain widget/s however relocate to another position when this is done.

I have both stored/retrieved entire parent DIVs containing the widget data as-well as stored/initialised serialized data as suggested by the Gridster documentation. I have noticed certain widgets seem to relocate when the widgets are stacked in a "long" position. If need be I can provide examples.

untitled

How can I prevent the relocating of the widgets? Any help will be greatly appreciated!

jlandry commented 10 years ago

I have noticed the same thing and would also like some help on this.

BarryatVendorpages commented 10 years ago

Yeah. I figured out why and solved it, uhm, when gridster accesses the dom to retrieves the widgets before it manipulates their position, it manipulates them one by one, starting from the widget declared from on the dom/first of the html... long story it initializes each widget, but when doing so, a widget declared at the top of the dom, whose actual position is near the bottom find its way back to top of the page during gridsters initialization...II save mine into a database in order, so when they come out they are in the correct... Ive got a function here somewhere... i haven't integrated it with gridsters code or anything yet because I dont have the time. Do you want the function? You can manipulate/change it to suite your circumstances...

ronnyek commented 10 years ago

This indeed was the cause of a very long running issue I've had. sorting by x, then y and loading iwdgets that way fixed the problem and things are running well. I wonder if theres a way we can prevent this in the code itself.

okydk commented 10 years ago

I'm using this simple sort function to do it on the client side, before looping and calling add_widget.

function compare(a,b) {
    if(a.col === b.col)
        return a.row - b.row;
    return a.col - b.col;
}
gridsterSetup.sort(compare);