Skip to content

Commit 888b8e0

Browse files
authored
Merge pull request #1668 from adumesny/develop
serialization of nested grid
2 parents 60d66c7 + bd50426 commit 888b8e0

22 files changed

+47
-26
lines changed

demo/nested.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ <h1>Nested grids demo</h1>
2424
<p>Note: initial v3 HTML5 release doesn't support 'dragOut:false' constrain so use jq version if you need that.</p>
2525
<a class="btn btn-primary" onClick="addNewWidget('.nested1')" href="#">Add Widget Grid1</a>
2626
<a class="btn btn-primary" onClick="addNewWidget('.nested2')" href="#">Add Widget Grid2</a>
27+
<a class="btn btn-primary" onClick="save()" href="#">Save</a>
28+
<a class="btn btn-primary" onClick="destroy()" href="#">Clear</a>
29+
<a class="btn btn-primary" onClick="load()" href="#">Load</a>
2730
<br><br>
2831
<!-- grid will be added here -->
2932
</div>
@@ -41,17 +44,16 @@ <h1>Nested grids demo</h1>
4144
minWidth: 300, // min to go 1 column mode
4245
margin: 1
4346
};
44-
let opts = {cellHeight: 70, children: [
47+
let json = {cellHeight: 70, children: [
4548
{y:0, content: 'regular item'},
4649
{x:1, w:4, h:4, content: 'nested 1 - can drag items out', subGrid: {children: sub1, dragOut: true, class: 'nested1', ...subOptions}},
4750
{x:5, w:4, h:4, content: 'nested 2 - constrained to parent (default)', subGrid: {children: sub2, class: 'nested2', ...subOptions}},
4851
]};
4952

5053
// create and load it all from JSON above
51-
GridStack.addGrid(document.querySelector('.container-fluid'), opts);
54+
let grid = GridStack.addGrid(document.querySelector('.container-fluid'), json);
5255

5356
addNewWidget = function(selector) {
54-
grid = document.querySelector(selector).gridstack;
5557
let node = {
5658
x: Math.round(12 * Math.random()),
5759
y: Math.round(5 * Math.random()),
@@ -62,6 +64,18 @@ <h1>Nested grids demo</h1>
6264
grid.addWidget(node);
6365
return false;
6466
};
67+
68+
save = function() {
69+
json = grid.save(true, true);
70+
}
71+
destroy = function() {
72+
grid.destroy();
73+
grid = undefined;
74+
}
75+
load = function() {
76+
grid = GridStack.addGrid(document.querySelector('.container-fluid'), json);
77+
}
78+
6579
</script>
6680
</body>
6781
</html>

doc/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [4.0.0-dev](#400-dev)
89
- [4.0.0 (2021-3-19)](#400-2021-3-19)
910
- [3.3.0 (2021-2-2)](#330-2021-2-2)
1011
- [3.2.0 (2021-1-25)](#320-2021-1-25)
@@ -48,6 +49,10 @@ Change log
4849
- [v0.1.0 (2014-11-18)](#v010-2014-11-18)
4950

5051
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
52+
## 4.0.0-dev
53+
54+
- fix [#1661](https://github.com/gridstack/gridstack.js/issues/1661) serialization of nested grid
55+
5156
## 4.0.0 (2021-3-19)
5257

5358
- fix [#149](https://github.com/gridstack/gridstack.js/issues/149) [#1094](https://github.com/gridstack/gridstack.js/issues/1094) [#1605](https://github.com/gridstack/gridstack.js/issues/1605) [#1534](https://github.com/gridstack/gridstack.js/issues/1534) re-write of the **collision code - fixing 6 years old most requested request**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gridstack",
3-
"version": "4.0.0",
3+
"version": "4.0.0-dev",
44
"description": "TypeScript/JS lib for dashboard layout and creation, no external dependencies, with many wrappers (React, Angular, Vue, Ember, knockout...)",
55
"main": "./dist/gridstack.js",
66
"types": "./dist/gridstack.d.ts",

src/gridstack-dd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack-GridStackDD.get().ts 4.0.0
1+
// gridstack-GridStackDD.get().ts 4.0.0-dev
22
// (c) 2021 Alain Dumesny - see root license
33
/* eslint-disable @typescript-eslint/no-unused-vars */
44
import { GridStackDDI } from './gridstack-ddi';

src/gridstack-ddi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack-ddi.ts 4.0.0
1+
// gridstack-ddi.ts 4.0.0-dev
22
// (c) 2021 Alain Dumesny - see root license
33
import { GridItemHTMLElement } from './types';
44

src/gridstack-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack-engine.ts 4.0.0
1+
// gridstack-engine.ts 4.0.0-dev
22
// (c) 2021 Alain Dumesny - see root license
33
import { Utils } from './utils';
44
import { GridStackNode, ColumnOptions, GridStackPosition, GridStackMoveOpts } from './types';

src/gridstack.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack.ts 4.0.0
1+
// gridstack.ts 4.0.0-dev
22
/*!
33
* (c) 2021 Alain Dumesny - see root license
44
*/
@@ -164,8 +164,10 @@ export class GridStack {
164164

165165
// create grid class and load any children
166166
let grid = GridStack.init(opt, el);
167-
if (opt.children) {
168-
grid.load(opt.children);
167+
if (grid.opts.children) {
168+
let children = grid.opts.children;
169+
delete grid.opts.children;
170+
grid.load(children);
169171
}
170172
return grid;
171173
}

src/h5/dd-base-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// dd-base-impl.ts 4.0.0
1+
// dd-base-impl.ts 4.0.0-dev
22
// (c) 2021 Alain Dumesny - see root license
33
export type EventCallback = (event: Event) => boolean|void;
44
export abstract class DDBaseImplement {

src/h5/dd-draggable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// dd-draggable.ts 4.0.0
1+
// dd-draggable.ts 4.0.0-dev
22
// (c) 2021 Alain Dumesny - see root license
33
import { DDManager } from './dd-manager';
44
import { DDUtils } from './dd-utils';

src/h5/dd-droppable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// dd-droppable.ts 4.0.0
1+
// dd-droppable.ts 4.0.0-dev
22
// (c) 2021 Alain Dumesny - see root license
33
import { DDDraggable } from './dd-draggable';
44
import { DDManager } from './dd-manager';

0 commit comments

Comments
 (0)