Skip to content

Update add_item function #188

@skworden

Description

@skworden

It would be nice if we could set min and max params as well as an ID when adding an element dynamically.

    GridStack.prototype.add_widget = function(el, x, y, width, height, auto_position, min_width, max_width, min_height, max_height, id) {
        el = $(el);
        if (typeof id != 'undefined') el.attr('id', id);
        if (typeof x != 'undefined') el.attr('data-gs-x', x);
        if (typeof y != 'undefined') el.attr('data-gs-y', y);
        if (typeof width != 'undefined') el.attr('data-gs-width', width);
        if (typeof height != 'undefined') el.attr('data-gs-height', height);
        if (typeof min_width != 'undefined') el.attr('data-gs-min-width', min_width);
        if (typeof max_width != 'undefined') el.attr('data-gs-max-width', max_width);
        if (typeof min_height != 'undefined') el.attr('data-gs-min-height', min_height);
        if (typeof max_height != 'undefined') el.attr('data-gs-max-height', max_height);
        if (typeof auto_position != 'undefined') el.attr('data-gs-auto-position', auto_position ? 'yes' : null);
        this.container.append(el);
        this._prepare_element(el);
        this._update_container_height();

        return el;
    };

//Example usage

grid.add_widget(el, 0, 0, 4, 1, true,3,12,1,1, 'example_id');


The ID would help for many reasons however, my use is being able to remove an element that was dynamically created and also when drawing the grid back out from the db.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions