How to make Gridster added widgets resizable?

你离开我真会死。 提交于 2019-12-02 03:36:37

I would try something like this:

$(document).on("click", "#add", function() {
var gridster = $(".layouts_grid ul").gridster().data('gridster');    

gridster.add_widget('<li class="layout_block" id="block" data-row="1" data-col="1" data-sizex="1" data-sizey="1"><div class="remove_element">X</div></li>', 1, 1);
    $('#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);
    } });

According to the documentation from Gridster you can use the resize property:

gridster.add_widget('<li class="layout_block" data-row="1" data-col="1" data-sizex="1" data-sizey="1"><div class="remove_element">X</div></li>', 1, 1)
    .resizable({ 
    ...
    stop: function(event, ui) {
        ...
    },
    resize: {
        enabled:true
    }
    ...
});

When you add the new widget, you just need to add the html code for the little arrow on the botom rigth corner... try something like this

var widget = gridster.add_widget('<li />', width, heigth, newWidgetCol, newWidgetRow);
var resizableWidgetHtml = '<span class="gs-resize-handle gs-resize-handle-both"></span>';
widget.attr('id', ui.draggable.id);
widget.html(htmlContent+resizableWidgetHtml);
widget.resize.enabled = true;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!