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.04k stars 1.2k forks source link

add_widget setting col and row generates crash #412

Open simplenotezy opened 10 years ago

simplenotezy commented 10 years ago

Hi there!

I have been fighting with a problem lately. Everything in gridster works. I can build up a very nice grid without problems. Then, when I save my grid in the database, and reload the page, it lags incredibly much. The more boxes, the more lag. It will cause the browser to crash. If theres few enough boxes, the page will load in 10-15 seconds, and then the grid will be perfect.

So I have spent hours narrowing down the problem, and I have found what causes this. When I import each grid box from the serialized data, I use this function:

add_widget(html, this.size_x, this.size_y, this.col, this.row); // this causes huge load time

If I remove this.col and this.row, it will load in less than a second:

add_widget(html, this.size_x, this.size_y); // this works perfectly

I am using version 0.5.5. Please note, that I have just upgraded from v0.5.1 where this issue did not exist. I think I remember it didn't work in 0.5.4 either.

I know you are super busy, but we're unable to launch our product, when we can't set col and row.

Thanks in advance!

simplenotezy commented 10 years ago

I have solved the problem. Well, a quickfix. If I remove the col and row from add_widget, and then instead add it to the HTML like this:

var html = $(html).attr('data-row', this.getData().row).attr('data-col', this.getData().col);

It works perfectly! Hurray!!

Chazmanian commented 10 years ago

canfiax - can you provide a snippet of code that demonstrates your fix. Specifically, does the $(html) selector represent the return you received from the add_widget call? I might have to do something similar to what you have been doing - that is, save and then restore a layout and it would be helpful if you shared. Thanks.

matheo commented 10 years ago

Cool, I'm about to work with many widgets and this is good to know. Would be good if the fix is documented properly :+1:

mobichel commented 9 years ago

I faced with same issue after upgrading to Gridster 0.5.2. Previously add_faux_rows() was called with undefined and we have no such problem.

Now add_faux_rows() method accepts size_y passed to add_widget() method. If you pass size_y as string it leads to incorrect calculation inside add_faux_rows() and your page become unresponsive.

Try to pass size_x and size_y as numbers when call add_widget method to solve this issue.