* initializing the HTML element, or selector string, into a grid will return the grid. Calling it again will * simply return the existing instance (ignore any passed options). There is also an initAll() version that support * multiple grids initialization at once. Or you can use addGrid() to c
(options: GridStackOptions = {}, elOrString: GridStackElement = '.grid-stack')
| 90 | * const grid = document.querySelector('.grid-stack').gridstack; |
| 91 | */ |
| 92 | public static init(options: GridStackOptions = {}, elOrString: GridStackElement = '.grid-stack'): GridStack { |
| 93 | if (typeof document === 'undefined') return null; // temp workaround SSR |
| 94 | const el = GridStack.getGridElement(elOrString); |
| 95 | if (!el) { |
| 96 | if (typeof elOrString === 'string') { |
| 97 | console.error('GridStack.initAll() no grid was found with selector "' + elOrString + '" - element missing or wrong selector ?' + |
| 98 | '\nNote: ".grid-stack" is required for proper CSS styling and drag/drop, and is the default selector.'); |
| 99 | } else { |
| 100 | console.error('GridStack.init() no grid element was passed.'); |
| 101 | } |
| 102 | return null; |
| 103 | } |
| 104 | if (!el.gridstack) { |
| 105 | el.gridstack = new GridStack(el, Utils.cloneDeep(options)); |
| 106 | } |
| 107 | return el.gridstack |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Will initialize a list of elements (given a selector) and return an array of grids. |
no test coverage detected