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

Grid height not correct when using add_widget method #460

Open tombrennand opened 9 years ago

tombrennand commented 9 years ago

I am inserting the content using the add_widget method as the widget content is pulled in from a database.

However, when the widgets are added, the height of the grid is not adjusted to the content - it stays as the min-rows that I have specified and the widget overflows the grid. and can cause widgets to overlap and be placed in the wrong positions too.

Here's my code:

var gridster2;

var serialization = [{
    "col": 1,
    "row": 1,
    "size_x": 4,
    "size_y": 29
}];

gridster2 = $(".gridster ul").gridster({
    widget_margins: [8, 8],
    widget_base_dimensions: [62, 62],
    widget_selector: "li",
    max_cols: 12,
    min_cols: 12,
    min_rows: 4,
    avoid_overlapped_widgets: true,
    resize: {
        enabled: false
    }
}).data('gridster').disable();

$.each(serialization, function (i, widget) {
    gridster2.add_widget('<li id="view_elem1"><span class="gridster_content">Hello world</span></li>', widget.size_x, widget.size_y, widget.col, widget.row);
});

Here's a jsfiddle - http://jsfiddle.net/62ewxm4g/

And here's a fiddle of the same content which is hard coded rather than using the add_widget method - http://jsfiddle.net/62ewxm4g/1/

Is this a bug or am I doing something wrong?

joshua-golub commented 9 years ago

Are you sorting the serialized information using Gridster.sort_by_row_and_col_asc before calling add_widget, as per this example? Make sure to view the source of the example.

tombrennand commented 9 years ago

I've tried it with and without sorting the serialized info... In my example there is only one widget to add anyway, so sorting it will not make a difference.

TitoVince35 commented 9 years ago

I've got the same problem. This is due to gridster's default behavior. Try to add your widgets by hand in the js console and you'll see what happens : if there is room for the newly added widget above it will be moved to the top. Is there any way to disable this behavior for a "free placing" of widgets? Thanks, anyone!