Skip to content

Commit bee6ff6

Browse files
committed
API make_widget functionality
1 parent fc571d8 commit bee6ff6

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
@@ -27,6 +27,7 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
2727
- [onresizestop(event, ui)](#onresizestopevent-ui)
2828
- [API](#api)
2929
- [add_widget(el, x, y, width, height, auto_position)](#add_widgetel-x-y-width-height-auto_position)
30+
- [make_widget(el)](#make_widgetel)
3031
- [batch_update()](#batch_update)
3132
- [cell_height()](#cell_height)
3233
- [cell_height(val)](#cell_heightval)
@@ -238,6 +239,23 @@ var grid = $('.grid-stack').data('gridstack');
238239
grid.add_widget(el, 0, 0, 3, 2, true);
239240
```
240241

242+
### make_widget(el)
243+
244+
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.
245+
Makes the given element a widget and returns it.
246+
247+
Parameters:
248+
249+
- `el` - element to convert to a widget
250+
251+
```javascript
252+
$('.grid-stack').gridstack();
253+
254+
$('.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>')
255+
var grid = $('.grid-stack').data('gridstack');
256+
grid.make_widget('gsi-1');
257+
```
258+
241259
### batch_update()
242260

243261
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
@@ -735,6 +735,15 @@
735735
return el;
736736
};
737737

738+
GridStack.prototype.make_widget = function(el) {
739+
el = $(el);
740+
this._prepare_element(el);
741+
this._update_container_height();
742+
this._trigger_change_event(true);
743+
744+
return el;
745+
};
746+
738747
GridStack.prototype.will_it_fit = function(x, y, width, height, auto_position) {
739748
var node = {x: x, y: y, width: width, height: height, auto_position: auto_position};
740749
return this.grid.can_be_placed_with_respect_to_height(node);

0 commit comments

Comments
 (0)