From e0d7e5080cd41b95372b89afbc4ae7d652853ec0 Mon Sep 17 00:00:00 2001 From: Alain Dumesny Date: Sun, 11 Jul 2021 08:59:43 -0700 Subject: [PATCH] save(false, false) fixes fix #1795 * save(false) will no longer have .content field fix #1782 * save(false, false) now correctly saves nested grids and not actual data structure * updated demos and test cases for these --- demo/float.html | 6 ++++++ demo/nested.html | 36 +++++++++++++++++++++++++----------- demo/serialization.html | 2 +- doc/CHANGES.md | 3 ++- doc/README.md | 2 +- spec/gridstack-spec.ts | 9 ++++++++- src/gridstack.ts | 34 +++++++++++++++------------------- src/utils.ts | 6 ++++-- 8 files changed, 62 insertions(+), 36 deletions(-) diff --git a/demo/float.html b/demo/float.html index 988bdd5da..36127464e 100644 --- a/demo/float.html +++ b/demo/float.html @@ -54,6 +54,12 @@

Float grid demo

document.querySelector('#float').innerHTML = 'float: ' + grid.getFloat(); }; addNewWidget(); + addNewWidget(); + + grid.enable(); + grid.save(false, true); // causes error at the end + grid.disable(); + grid.enable(); diff --git a/demo/nested.html b/demo/nested.html index a11a243ab..4ce44881f 100644 --- a/demo/nested.html +++ b/demo/nested.html @@ -21,13 +21,19 @@

Nested grids demo

This example uses new v3.1 API to load the entire nested grid from JSON, and shows dragging between nested grid items (pink) vs dragging higher grid items (green)

-

Note: initial v3 HTML5 release doesn't support 'dragOut:false' constrain so use jq version if you need that.

+

Note: HTML5 release doesn't yet support 'dragOut:false' constrain so use JQ version if you need that.

Add Widget Add Widget Grid1 Add Widget Grid2 + entire save/re-create: Save - Clear - Load + Destroy + Create + partial save/load: + Save list + Save no content + Clear + Load

@@ -45,7 +51,7 @@

Nested grids demo

minWidth: 300, // min to go 1 column mode margin: 1 }; - let json = {cellHeight: 70, children: [ + let json = {cellHeight: 70, minRow: 2, children: [ {y:0, content: 'regular item'}, {x:1, w:4, h:4, content: 'nested 1 - can drag items out', subGrid: {children: sub1, dragOut: true, class: 'nested1', ...subOptions}}, {x:5, w:4, h:4, content: 'nested 2 - constrained to parent (default)', subGrid: {children: sub2, class: 'nested2', ...subOptions}}, @@ -71,17 +77,25 @@

Nested grids demo

return false; }; - save = function() { - json = grid.save(false, true); + save = function(content = true, full = true) { + json = grid.save(content, full); console.log(json); // console.log(JSON.stringify(json)); } - destroy = function() { - grid.destroy(); - grid = undefined; + destroy = function(full = true) { + if (full) { + grid.destroy(); + grid = undefined; + } else { + grid.removeAll(); + } } - load = function() { - grid = GridStack.addGrid(document.querySelector('.container-fluid'), json); + load = function(full = true) { + if (full) { + grid = GridStack.addGrid(document.querySelector('.container-fluid'), json); + } else { + grid.load(json); + } } diff --git a/demo/serialization.html b/demo/serialization.html index b97141626..32ed5be0f 100644 --- a/demo/serialization.html +++ b/demo/serialization.html @@ -24,7 +24,7 @@

Serialization demo