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.03k stars 1.2k forks source link

adding OPTION: min_size_x & min_size_y #248

Open chullski opened 11 years ago

chullski commented 11 years ago

Would be great to define the "min_size_x & min_size_y" of a widget like the corresponding "max_size_x & max-size_y" size restrictions.

kenijo commented 10 years ago

Do it this way:

var minWidth = 150;
var minHeight = 100;
gridster = $('.gridster ul').gridster({
    widget_base_dimensions: [minWidth, minHeight],
    widget_margins: [5, 5],
    helper: 'clone',
    resize: {
        enabled: true,
        max_size: [5, 5],
        resize: function (event, ui, $widget) {
            if ($widget.width() <= minWidth) {
                $widget.width(minWidth);
            }
            if ($widget.height() <= minHeight) {
                $widget.height(minHeight);
            }
        }
    }
}).data('gridster');
lgm42 commented 10 years ago

It doesn't work because during your mouse is resizing it's okay, but if you even go smaller that it is authorized and you release the click it resize.

To reproduce that I have set minWith and minHeight to 200 and widget_base_dimensions to 100

kenijo commented 10 years ago

I'm not sure I understand, look at this example, it's working fine: http://jsfiddle.net/RzLf5/6/

If you want to prevent the resizing when you release your mouse button in a zone that is smaller than your authorized size, you can always put a check like this:

resize: {
    start: function (event, ui, $widget) {
        original_width = $widget.width();
        original_height = $widget.height();
    }
    stop: function (event, ui, $widget) {
        if ($widget.width() <= minWidth) {
            $widget.width(original_width);
        }
        if ($widget.height() <= minHeight) {
            $widget.height(original_height);
        }
    }
}
ibarnes commented 10 years ago

How would you limit the widgets min-width to be the width of input items inside of a widget. I forked your jsfiddle here: http://jsfiddle.net/isaacbarnes/tSdRb/. If you click add widget you can see what I'm asking.

kenijo commented 10 years ago

I would suggest to surround your content with a

and then resize the widget to the width and height of the div after it's creation. I don't have the time to update the fiddle right now, I'll see what I can do next week

ibarnes commented 10 years ago

Kenijo thanks I appreciate it. I tried that but the user can still resize the grid to be smaller than the width of the field within the widget. I basically want to set the min height and min width of one widget. This would be a great addition to gridster. I'm sure I won't be the only person asking for it.

dmattes commented 10 years ago

Hey Kenijo, can you take a look on my pull request, it adds min_height and min_width to a widget. https://github.com/ducksboard/gridster.js/pull/275 Best, Daniel

kenijo commented 10 years ago

@dmattes: It looks great but I'm not part of this project, I can't do anything about it.

kenijo commented 10 years ago

@ibarnes : Check this fiddle http://jsfiddle.net/RzLf5/7/ I get the width of the textbox and then use it to calculate the width of the widget the same way I did for the height.

ibarnes commented 10 years ago

Thanks.