* call to create a grid with the given options, including loading any children from JSON structure. This will call GridStack.init(), then * grid.load() on any passed children (recursively). Great alternative to calling init() if you want entire grid to come from * JSON serialized data, includi
(parent: HTMLElement, opt: GridStackOptions = {})
| 140 | * @param opt grids options used to initialize the grid, and list of children |
| 141 | */ |
| 142 | public static addGrid(parent: HTMLElement, opt: GridStackOptions = {}): GridStack { |
| 143 | if (!parent) return null; |
| 144 | |
| 145 | let el = parent as GridHTMLElement; |
| 146 | if (el.gridstack) { |
| 147 | // already a grid - set option and load data |
| 148 | const grid = el.gridstack; |
| 149 | if (opt) grid.opts = { ...grid.opts, ...opt }; |
| 150 | if (opt.children !== undefined) grid.load(opt.children); |
| 151 | return grid; |
| 152 | } |
| 153 | |
| 154 | // create the grid element, but check if the passed 'parent' already has grid styling and should be used instead |
| 155 | const parentIsGrid = parent.classList.contains('grid-stack'); |
| 156 | if (!parentIsGrid || GridStack.addRemoveCB) { |
| 157 | if (GridStack.addRemoveCB) { |
| 158 | el = GridStack.addRemoveCB(parent, opt, true, true); |
| 159 | } else { |
| 160 | el = Utils.createDiv(['grid-stack', opt.class], parent); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // create grid class and load any children |
| 165 | const grid = GridStack.init(opt, el); |
| 166 | return grid; |
| 167 | } |
| 168 | |
| 169 | /** call this method to register your engine instead of the default one. |
| 170 | * See instead `GridStackOptions.engineClass` if you only need to |
no test coverage detected