You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
This code has now been implemented. You may pass minWidth, maxWidth, minHeight, maxHeight, and id to addWidget now. Please note that gridstack will not write the id value onto the element id. Instead, it will use data-gs-id, as is common to this library.
Activity
h-nazzal commentedon Jul 31, 2015
for better performance it should be
skworden commentedon Jul 31, 2015
agreed @h-nazzal . I just kept it how they had it originally.
radiolips commentedon Feb 22, 2016
This code has now been implemented. You may pass
minWidth,maxWidth,minHeight,maxHeight, andidtoaddWidgetnow. Please note that gridstack will not write the id value onto the element id. Instead, it will usedata-gs-id, as is common to this library.