Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5e84ae

Browse files
committed
added second nested demo
1 parent 83e11d2 commit d5e84ae

File tree

2 files changed

+117
-7
lines changed

2 files changed

+117
-7
lines changed

demo/index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@
77
<body>
88
<h1>Demos</h1>
99
<ul>
10-
<li><a href="anijs.html">AniJS</a></li>
11-
<li><a href="angular.ts">Angular (simple)</a></li>
1210
<li><a href="angular-ngFor.ts">Angular (ngFor partial)</a></li>
11+
<li><a href="angular.ts">Angular (simple)</a></li>
12+
<li><a href="anijs.html">AniJS</a></li>
1313
<li><a href="cell-height.html">Cell Height</a></li>
1414
<li><a href="column.html">Column</a></li>
1515
<li><a href="float.html">Float grid</a></li>
1616
<li><a href="knockout.html">Knockout.js</a></li>
17+
<li><a href="mobile.html">Mobile touch (JQ)</a></li>
1718
<li><a href="nested.html">Nested grids</a></li>
18-
<li><a href="responsive.html">Responsive</a></li>
19-
<li><a href="react.html">ReactJS</a></li>
19+
<li><a href="nested_advanced.html">Nested Advanced grids</a></li>
2020
<li><a href="react-hooks.html">ReactJS (Hooks)</a></li>
21+
<li><a href="react.html">ReactJS</a></li>
22+
<li><a href="responsive.html">Responsive</a></li>
2123
<li><a href="right-to-left(rtl).html">Right-To-Left (RTL)</a></li>
2224
<li><a href="serialization.html">Serialization</a></li>
2325
<li><a href="static.html">Static</a></li>
2426
<li><a href="two.html">Two grids</a></li>
2527
<li><a href="two_vertical.html">Two grids Vertical</a></li>
26-
<li><a href="mobile.html">Mobile touch (JQ)</a></li>
27-
<li><a href="vue3js.html">Vue3.js</a></li>
2828
<li><a href="vue2js.html">Vue2.js</a></li>
29+
<li><a href="vue3js.html">Vue3.js</a></li>
30+
<li><a href="web-comp.html">Web Component</a></li>
2931
<li><a href="web1.html">Website demo 1</a></li>
3032
<li><a href="web2.html">Website demo 2</a></li>
31-
<li><a href="web-comp.html">Web Component</a></li>
3233
</ul>
3334
</body>
3435
</html>

demo/nested_advanced.html

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Nested grids demo (ES6)</title>
8+
<link rel="stylesheet" href="demo.css"/>
9+
<link rel="stylesheet" href="../dist/gridstack-extra.min.css"/>
10+
<script src="../dist/gridstack-h5.js"></script>
11+
<style type="text/css">
12+
.grid-stack.grid-stack-nested {
13+
background: rgba(255, 255, 255, 0.3);
14+
}
15+
.grid-stack-item.sub .grid-stack-item-content {
16+
background: lightpink;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<div class="container-fluid">
22+
<h1>Advanced Nested grids demo</h1>
23+
<p>This example shows sub-grids only accepting pink items, while parent accept all.</p>
24+
<a class="btn btn-primary" onClick="addNested()" href="#">Add Widget</a>
25+
<a class="btn btn-primary" onClick="addNewWidget('.sub1')" href="#">Add Widget Grid1</a>
26+
<a class="btn btn-primary" onClick="addNewWidget('.sub2')" href="#">Add Widget Grid2</a>
27+
<span>entire save/re-create:</span>
28+
<a class="btn btn-primary" onClick="save()" href="#">Save</a>
29+
<a class="btn btn-primary" onClick="destroy()" href="#">Destroy</a>
30+
<a class="btn btn-primary" onClick="load()" href="#">Create</a>
31+
<span>partial save/load:</span>
32+
<a class="btn btn-primary" onClick="save(true, false)" href="#">Save list</a>
33+
<a class="btn btn-primary" onClick="save(false, false)" href="#">Save no content</a>
34+
<a class="btn btn-primary" onClick="destroy(false)" href="#">Clear</a>
35+
<a class="btn btn-primary" onClick="load(false)" href="#">Load</a>
36+
<br><br>
37+
<!-- grid will be added here -->
38+
</div>
39+
40+
<script type="text/javascript">
41+
let sub1 = [ {x:0, y:0}, {x:1, y:0}, {x:2, y:0}, {x:3, y:0}, {x:0, y:1}, {x:1, y:1}];
42+
let sub2 = [ {x:0, y:0}, {x:0, y:1, w:2}];
43+
let count = 0;
44+
[...sub1, ...sub2].forEach(d => d.content = String(count++));
45+
let subOptions = {
46+
cellHeight: 50,
47+
column: 'auto', // size to match container. make sure to include gridstack-extra.min.css
48+
itemClass: 'sub', // style sub items differently and use to prevent dragging in/out
49+
acceptWidgets: '.grid-stack-item.sub', // only pink sub items can be inserted
50+
margin: 2,
51+
minRow: 1, // don't collapse when empty
52+
};
53+
let options = { // main grid options
54+
cellHeight: 50,
55+
margin: 5,
56+
minRow: 2, // don't collapse when empty
57+
acceptWidgets: true,
58+
id: 'main',
59+
children: [
60+
{y:0, content: 'regular item'},
61+
{x:1, w:4, h:4, content: 'nested 1 - can drag items out', subGrid: {children: sub1, dragOut: true, class: 'sub1', ...subOptions}},
62+
{x:5, w:4, h:4, content: 'nested 2 - constrained to parent (JQ only)', subGrid: {children: sub2, class: 'sub2', ...subOptions}},
63+
]
64+
};
65+
66+
// create and load it all from JSON above
67+
let grid = GridStack.addGrid(document.querySelector('.container-fluid'), options);
68+
69+
addNested = function() {
70+
grid.addWidget({x:0, y:100, content:"new item"});
71+
}
72+
73+
addNewWidget = function(selector) {
74+
let subGrid = document.querySelector(selector).gridstack;
75+
let node = {
76+
x: Math.round(6 * Math.random()),
77+
y: Math.round(5 * Math.random()),
78+
w: Math.round(1 + 1 * Math.random()),
79+
h: Math.round(1 + 1 * Math.random()),
80+
content: String(count++)
81+
};
82+
subGrid.addWidget(node);
83+
return false;
84+
};
85+
86+
save = function(content = true, full = true) {
87+
options = grid.save(content, full);
88+
console.log(options);
89+
// console.log(JSON.stringify(options));
90+
}
91+
destroy = function(full = true) {
92+
if (full) {
93+
grid.destroy();
94+
grid = undefined;
95+
} else {
96+
grid.removeAll();
97+
}
98+
}
99+
load = function(full = true) {
100+
if (full) {
101+
grid = GridStack.addGrid(document.querySelector('.container-fluid'), options);
102+
} else {
103+
grid.load(options);
104+
}
105+
}
106+
107+
</script>
108+
</body>
109+
</html>

0 commit comments

Comments
 (0)