Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drag an element from one gridster to another? [closed]

Has anybody tried to drag a cell from one Gridster to another? I have been trying to get that working.. but with no luck. Any help please?

like image 354
Vaibhav Pingle Avatar asked Oct 22 '22 07:10

Vaibhav Pingle


1 Answers

Here is an example of drag / drop into a gridster. It is only half of what you are asking for but I suspect one could watch an item for dragging outside of its gridster and into another..

Here is an example of moving items from one grid to another via a double click. It's a start.

$(function () { //DOM Ready

$(".gridster ul").gridster({
    widget_margins: [5, 5],
    widget_base_dimensions: [100, 120]
});

var gridster = $(".gridster ul").gridster().data('gridster');
var gridster2 = $(".gridster2 ul").gridster().data('gridster');

$("#dragFrom").draggable();

$(".gridster ").droppable({
    drop: function (event, ui) {

        $("#dragFrom").attr("style", 'position: relative;');
        var widget = gridster.add_widget('<li><h5>Ukulele Boat</h5><img height=100 width=100 src="http://i.imgur.com/XjNt15P.jpg" alt="Uke Boat" ></li>', 1, 1);
        widget.dblclick(function (widget) {
            widget = gridster.remove_widget(this);
            var gridster2 = $(".gridster2 ul").gridster().data('gridster');
            widget = gridster2.add_widget('<li id="draggable2"><h5>Ukulele Boat</h5><img height=100 width=100 src="http://i.imgur.com/XjNt15P.jpg" alt="Uke Boat" ></li>', 1, 1);
            widget.dblclick(function (widget) {
                gridster2.remove_widget(this);
            });
        });
    }
});

$(".gridster2 ").droppable({
    drop: function (event, ui) {

        var widget = gridster2.add_widget('<li id="draggable2"><h5>Electric Goldfish</h5><img height=100 width=100 src=http://i.imgur.com/OYfuMLF.jpg" alt="Electric Goldfish"  ></li>', 1, 1);
        widget.dblclick(function (widget) {
            widget = gridster2.remove_widget(this);
            var gridster = $(".gridster ul").gridster().data('gridster');
            widget = gridster.add_widget('<li id="draggable2"><h5>Electric Goldfish</h5><img height=100 width=100 src=http://i.imgur.com/OYfuMLF.jpg" alt="Electric Goldfish" ></li>', 1, 1);
            widget.dblclick(function (widget) {
                gridster.remove_widget(this);
            });
        });
        $("#dragFrom").attr("style", 'position: relative;');

    }
});

});

like image 160
IntStarFoo Avatar answered Nov 01 '22 10:11

IntStarFoo