Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a single widget from gridster.js by his dynamically created id

I need to know how can I remove a single gridster.js widget by his dynamically created id with gridster.add_widget. Every new widget created has an own button to remove that single widget, but I can't make it work.

Here is my Code

$(document).ready(function(){

var count = 0;
var newid = count + 1;

    $(document).on("click", "#newGrid", function() {
        var gridster = $(".gridster ul").gridster().data('gridster');
        gridster.add_widget('<li id="block"'+newid'>Hello, now delete me <span id="remove"'+newid'>x</span></li>',2 ,1);
    });

    $(document).on('click', '#remove'+newid, function() {
    var gridster = $(".gridster ul").gridster().data('gridster');
        gridster.remove_widget( '#block'+newid );
    });

});

For adding widgets it works fine, but I can't remove widgets.

like image 217
iamrobertsillo Avatar asked Mar 22 '23 05:03

iamrobertsillo


1 Answers

Actually you don't need ID for widget removing. Please check my script.

    var gridster = $('.gridster ul').gridster().data('gridster');
    $(document).on( "click", ".gridster ul li", function() {
        $(this).addClass("activ");
        gridster.remove_widget($('.activ'));
    });
like image 160
minimal Avatar answered Apr 27 '23 13:04

minimal