Question

Is it possible to make only one gridster widget resizable?

I've made it so the user can click on a widget heading so that it expands & contracts.

I'd like to make it so that when a widget is expanded, it is resizable.

Can this be done? If so, how?

Was it helpful?

Solution 2

When resize is enable each widget get the gs-resize-handle class in a span element with the setup_resize() function.

so you can play with css to hide the resize handle with css by adding a custom class like :

.no-resize .gs-resize-handle-both{
   display:none;
}

and when you expand your widget your remove your custom class.

EDIT :

An another way to do this could be like in the demo on gridster expandable demo with a some change on the click event.

OTHER TIPS

You can have only some "specific" widgets resizable modifying (only 4 lines of) the library as follows ( refer to gridster.js - v0.5.1 - 2014-03-26) ..

1) Update the add_widget function (modified lines are marked as "custom" in the comments):

fn.add_widget = function(html, size_x, size_y, col, row, max_size, min_size, resizable) { //custom
        var pos;
        size_x || (size_x = 1);
        size_y || (size_y = 1);

        if (!col & !row) {
            pos = this.next_position(size_x, size_y);
        }else{
            pos = {
                col: col,
                row: row
            };

            this.empty_cells(col, row, size_x, size_y);
        }

        var $w = $(html).attr({
                'resizable' : (resizable === true), //custom
                'data-col': pos.col,
                'data-row': pos.row,
                'data-sizex' : size_x,
                'data-sizey' : size_y
            }).addClass('gs-w').appendTo(this.$el).hide();

[...]

2) update the register_widget function (again, mind the word "custom" in the comments):

fn.register_widget = function($el) {
        var resizable = $el.attr('resizable'); //custom
        var wgd = {
            'col': parseInt($el.attr('data-col'), 10),
            'row': parseInt($el.attr('data-row'), 10),
            'size_x': parseInt($el.attr('data-sizex'), 10),
            'size_y': parseInt($el.attr('data-sizey'), 10),
            'max_size_x': parseInt($el.attr('data-max-sizex'), 10) || false,
            'max_size_y': parseInt($el.attr('data-max-sizey'), 10) || false,
            'min_size_x': parseInt($el.attr('data-min-sizex'), 10) || false,
            'min_size_y': parseInt($el.attr('data-min-sizey'), 10) || false,
            'el': $el
        };

        if (this.options.avoid_overlapped_widgets &&
            !this.can_move_to(
             {size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
        ) {
            $.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
            $el.attr({
                'data-col': wgd.col,
                'data-row': wgd.row,
                'data-sizex': wgd.size_x,
                'data-sizey': wgd.size_y
            });
        }

        // attach Coord object to player data-coord attribute
        $el.data('coords', $el.coords());
        // Extend Coord object with grid position info
        $el.data('coords').grid = wgd;

        this.add_to_gridmap(wgd, $el);
        this.options.resize.enabled && (resizable === "true") && this.add_resize_handle($el); //custom

        return this;
    };

Done!

The new signature of the add_widget function is now:

.add_widget( html, [size_x], [size_y], [col], [row], [resizable] )

Just set "resizable" parameter to true if you want a widget to be resizable!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top