MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / makeWidget

Method makeWidget

src/gridstack.ts:1256–1281  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 6

addWidgetMethod · 0.95
makeSubGridMethod · 0.95
ngAfterViewInitMethod · 0.80
ngAfterViewInitMethod · 0.80
removeAsSubGridMethod · 0.80
gridstack-spec.tsFile · 0.80

Calls 6

_prepareElementMethod · 0.95
makeSubGridMethod · 0.95
_triggerAddEventMethod · 0.95
_triggerChangeEventMethod · 0.95
getElementMethod · 0.45

Tested by

no test coverage detected