4

I'm using the Gridster Plugin(http://gridster.net). I found an updated demo at Github of this which is resizable. I have also added the jQuery livequery plugin in order to go well with the future items.

After adding new grid items, either dragable/resizable is working. Default Items are working fine, only the problem with new items. This is how I'm using the code:

Resize + Drag

var layout;
var grid_size = 30;
var grid_margin =5;

$(function() {
    layout = $('.layouts_grid ul').gridster({
        widget_margins: [grid_margin, grid_margin],
        widget_base_dimensions: [grid_size, grid_size],
        serialize_params: function($w, wgd) {
            return {
                x: wgd.col,
                y: wgd.row,
                width: wgd.size_x,
                height: wgd.size_y,
                id: $($w).attr('data-id'),
                name: $($w).find('.block_name').html(),
            };
        },
        min_rows: block_params.max_height
    }).data('gridster');

    $('.layout_block').livequery(function(){
        $('.layout_block').resizable({
            grid: [grid_size + (grid_margin * 2), grid_size + (grid_margin * 2)],
            animate: false,
            minWidth: grid_size,
            minHeight: grid_size,
            containment: '#layouts_grid ul',
            autoHide: true,
            stop: function(event, ui) {
                var resized = $(this);
                setTimeout(function() {
                    resizeBlock(resized);
                }, 300);
            }
        });
    });

    //This works only for default items
    $('.ui-resizable-handle').hover(function() {
        layout.disable();
    }, function() {
        layout.enable();
    });
});

Adding Item

$('#add').click(function(){
     var tmpP = '<li class="layout_block new ui-resizable ui-resizable-autohide" style="background-color: #B60000;">New one</li>'
     var gridster = $(".layouts_grid ul").gridster().data('gridster');
     gridster.add_widget(tmpP, 2, 1);
});

Please Check the JSFiddle as well http://jsfiddle.net/PrtrR/51/

Please help me do this.

Regards.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1915190
  • 307
  • 1
  • 2
  • 14

2 Answers2

1

I'd highly recommend using jQueryUI Sortable's grid example:

http://jqueryui.com/sortable/#display-grid

professormeowingtons
  • 3,504
  • 7
  • 36
  • 50
0
$('#add').click(function(){
     var tmpP = '<li class="gs_w layout_block new ui-resizable ui-resizable-autohide" style="background-color: #B60000;">New one</li>'
    var gridster = $(".layouts_grid ul").gridster().data('gridster');
    gridster.add_widget(tmpP, 2, 1);
 });

Please add class="gs_w" in <li> tag attribute as I did above

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
ferozcoder
  • 454
  • 5
  • 18