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

Method save

src/gridstack-engine.ts:1018–1041  ·  view source on GitHub ↗

saves a copy of the largest column layout (eg 12 even when rendering 1 column) so we don't loose orig layout, unless explicity column * count to use is given. returning a list of widgets for serialization * @param saveElement if true (default), the element will be saved to GridStackWidget.el f

(saveElement = true, saveCB?: SaveFcn, column?: number)

Source from the content-addressed store, hash-verified

1016 * Note: nested grids will ALWAYS save the container w to match overall layouts (parent + child) to be consistent.
1017 */
1018 public save(saveElement = true, saveCB?: SaveFcn, column?: number): GridStackNode[] {
1019 // use the highest layout for any saved info so we can have full detail on reload #1849
1020 // unless we're given a column to match (always set for nested grids)
1021 const len = this._layouts?.length || 0;
1022 let layout: GridStackNode[];
1023 if (len) {
1024 if (column) {
1025 if (column !== this.column) layout = this._layouts[column];
1026 } else if (this.column !== len - 1) {
1027 layout = this._layouts[len - 1];
1028 }
1029 }
1030 const list: GridStackNode[] = [];
1031 this.sortNodes();
1032 this.nodes.forEach(n => {
1033 const wl = layout?.find(l => l._id === n._id);
1034 // use layout info fields instead if set
1035 const w: GridStackNode = {...n, ...(wl || {})};
1036 Utils.removeInternalForSave(w, !saveElement);
1037 if (saveCB) saveCB(n, w);
1038 list.push(w);
1039 });
1040 return list;
1041 }
1042
1043 /** @internal called whenever a node is added or moved - updates the cached layouts */
1044 public layoutsNodesChange(nodes: GridStackNode[]): GridStackEngine {

Callers

nothing calls this directly

Calls 3

sortNodesMethod · 0.95
findMethod · 0.80
removeInternalForSaveMethod · 0.80

Tested by

no test coverage detected