* 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. * If you want gridstack to add the elements for you, use `addWidget()` instead. * Makes the given element a widget and returns it. * * @param els
(els: GridStackElement, options?: GridStackWidget)
| 1254 | * grid.makeWidget(element, {x: 0, y: 1, w: 4, h: 2}); |
| 1255 | */ |
| 1256 | public makeWidget(els: GridStackElement, options?: GridStackWidget): GridItemHTMLElement { |
| 1257 | const el = GridStack.getElement(els); |
| 1258 | if (!el || el.gridstackNode) return el; |
| 1259 | if (!el.parentElement) this.el.appendChild(el); |
| 1260 | this._prepareElement(el, true, options); |
| 1261 | const node = el.gridstackNode; |
| 1262 | |
| 1263 | this._updateContainerHeight(); |
| 1264 | |
| 1265 | // see if there is a sub-grid to create |
| 1266 | if (node.subGridOpts) { |
| 1267 | this.makeSubGrid(el, node.subGridOpts, undefined, false); // node.subGrid will be used as option in method, no need to pass |
| 1268 | } |
| 1269 | |
| 1270 | // if we're adding an item into 1 column make sure |
| 1271 | // we don't override the larger 12 column layout that was already saved. #1985 |
| 1272 | let resetIgnoreLayoutsNodeChange: boolean; |
| 1273 | if (this.opts.column === 1 && !this._ignoreLayoutsNodeChange) { |
| 1274 | resetIgnoreLayoutsNodeChange = this._ignoreLayoutsNodeChange = true; |
| 1275 | } |
| 1276 | this._triggerAddEvent(); |
| 1277 | this._triggerChangeEvent(); |
| 1278 | if (resetIgnoreLayoutsNodeChange) delete this._ignoreLayoutsNodeChange; |
| 1279 | |
| 1280 | return el; |
| 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * Register event handler for grid events. You can call this on a single event name, or space separated list. |
no test coverage detected