Skip to content

Commit 90424c0

Browse files
committed
Merge pull request #264 from kdietrich/make-widget
Adding make_widget functionality
2 parents d42b8c7 + bee6ff6 commit 90424c0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Join gridstack.js on Slack: https://gridstackjs.troolee.com
3232
- [enable(event)](#enableevent)
3333
- [API](#api)
3434
- [add_widget(el, x, y, width, height, auto_position)](#add_widgetel-x-y-width-height-auto_position)
35+
- [make_widget(el)](#make_widgetel)
3536
- [batch_update()](#batch_update)
3637
- [cell_height()](#cell_height)
3738
- [cell_height(val)](#cell_heightval)
@@ -257,6 +258,23 @@ var grid = $('.grid-stack').data('gridstack');
257258
grid.add_widget(el, 0, 0, 3, 2, true);
258259
```
259260

261+
### make_widget(el)
262+
263+
If you add elements to your gridstack container by hand, you have to tell gridstack afterwards to make them widgets. If you want gridstack to add the elements for you, use `add_widget` instead.
264+
Makes the given element a widget and returns it.
265+
266+
Parameters:
267+
268+
- `el` - element to convert to a widget
269+
270+
```javascript
271+
$('.grid-stack').gridstack();
272+
273+
$('.grid-stack').append('<div id="gsi-1" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="2" data-gs-auto-position="1"></div>')
274+
var grid = $('.grid-stack').data('gridstack');
275+
grid.make_widget('gsi-1');
276+
```
277+
260278
### batch_update()
261279

262280
Initailizes batch updates. You will see no changes until `commit` method is called.

src/gridstack.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,15 @@
747747
return el;
748748
};
749749

750+
GridStack.prototype.make_widget = function(el) {
751+
el = $(el);
752+
this._prepare_element(el);
753+
this._update_container_height();
754+
this._trigger_change_event(true);
755+
756+
return el;
757+
};
758+
750759
GridStack.prototype.will_it_fit = function(x, y, width, height, auto_position) {
751760
var node = {x: x, y: y, width: width, height: height, auto_position: auto_position};
752761
return this.grid.can_be_placed_with_respect_to_height(node);

0 commit comments

Comments
 (0)