Skip to content

Commit 8918171

Browse files
authored
Merge pull request #1875 from adumesny/master
save full res in 1 column mode
2 parents 3c2d242 + d8b6d25 commit 8918171

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Change log
6565

6666
## 4.3.0-dev (TBD)
6767
* fix [#1868](https://github.com/gridstack/gridstack.js/issues/1868) prevent swap during resize
68+
* fix [#1849](https://github.com/gridstack/gridstack.js/issues/1849) [#1816](https://github.com/gridstack/gridstack.js/issues/1816) save highest resolution in 1 column mode
6869

6970
## 4.3.0 (2021-10-15)
7071
* you can now swap items of different width if they are the same row/height. Thanks to [spektrummedia](http://spektrummedia.com) for sponsoring it.

src/gridstack-engine.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,21 @@ export class GridStackEngine {
667667
return this;
668668
}
669669

670-
/** saves a copy of the current layout returning a list of widgets for serialization */
670+
/** saves a copy of the largest column layout (eg 12 even when rendering oneColumnMode, so we don't loose orig layout),
671+
* returning a list of widgets for serialization */
671672
public save(saveElement = true): GridStackNode[] {
673+
// use the highest layout for any saved info so we can have full detail on reload #1849
674+
let len = this._layouts?.length;
675+
let layout = len && this.column !== (len - 1) ? this._layouts[len - 1] : null;
672676
let list: GridStackNode[] = [];
673677
this._sortNodes();
674678
this.nodes.forEach(n => {
675-
let w: GridStackNode = {};
676-
for (let key in n) { if (key[0] !== '_' && n[key] !== null && n[key] !== undefined ) w[key] = n[key]; }
677-
// delete other internals
679+
let wl = layout?.find(l => l._id === n._id);
680+
let w: GridStackNode = {...n};
681+
// use layout info instead if set
682+
if (wl) { w.x = wl.x; w.y = wl.y; w.w = wl.w; }
683+
// delete internals
684+
for (let key in w) { if (key[0] === '_' || w[key] === null || w[key] === undefined ) delete w[key]; }
678685
delete w.grid;
679686
if (!saveElement) delete w.el;
680687
// delete default values (will be re-created on read)

0 commit comments

Comments
 (0)