Skip to content

Commit cdf7796

Browse files
committed
makeWidget() now take optional GridStackWidget for sizing
1 parent 1d62440 commit cdf7796

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

doc/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [8.1.2-dev TBD](#812-dev-tbd)
89
- [8.1.2 (2023-5-22)](#812-2023-5-22)
910
- [8.1.1 (2023-05-13)](#811-2023-05-13)
1011
- [8.1.0 (2023-05-06)](#810-2023-05-06)
@@ -86,6 +87,10 @@ Change log
8687
- [v0.1.0 (2014-11-18)](#v010-2014-11-18)
8788

8889
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
90+
91+
## 8.1.2-dev TBD
92+
* feat: `makeWidget()` now take optional `GridStackWidget` for sizing
93+
8994
## 8.1.2 (2023-5-22)
9095
* [#2323](https://github.com/gridstack/gridstack.js/issues/2323) module for Angular wrapper
9196

src/gridstack.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,19 +965,22 @@ export class GridStack {
965965
}
966966

967967
/**
968-
* If you add elements to your grid by hand, you have to tell gridstack afterwards to make them widgets.
968+
* If you add elements to your grid by hand (or have some framework creating DOM), you have to tell gridstack afterwards to make them widgets.
969969
* If you want gridstack to add the elements for you, use `addWidget()` instead.
970970
* Makes the given element a widget and returns it.
971971
* @param els widget or single selector to convert.
972+
* @param options widget definition to use instead of reading attributes or using default sizing values
972973
*
973974
* @example
974975
* let grid = GridStack.init();
975-
* grid.el.appendChild('<div id="gsi-1" gs-w="3"></div>');
976-
* grid.makeWidget('#gsi-1');
976+
* grid.el.appendChild('<div id="1" gs-w="3"></div>');
977+
* grid.el.appendChild('<div id="2"></div>');
978+
* grid.makeWidget('1');
979+
* grid.makeWidget('2', {w:2, content: 'hello'});
977980
*/
978-
public makeWidget(els: GridStackElement): GridItemHTMLElement {
981+
public makeWidget(els: GridStackElement, options?: GridStackWidget): GridItemHTMLElement {
979982
let el = GridStack.getElement(els);
980-
this._prepareElement(el, true);
983+
this._prepareElement(el, true, options);
981984
this._updateContainerHeight();
982985
this._triggerAddEvent();
983986
this._triggerChangeEvent();
@@ -1072,6 +1075,10 @@ export class GridStack {
10721075
}
10731076
if (!node) return;
10741077

1078+
if (GridStack.addRemoveCB) {
1079+
GridStack.addRemoveCB(this.el, node, false, false);
1080+
}
1081+
10751082
// remove our DOM data (circular link) and drag&drop permanently
10761083
delete el.gridstackNode;
10771084
this._removeDD(el);

0 commit comments

Comments
 (0)