|
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
7 | 7 | <title>Nested grids demo (ES6)</title> |
8 | 8 | <link rel="stylesheet" href="demo.css"/> |
| 9 | + <link rel="stylesheet" href="../dist/gridstack-extra.min.css"/> |
9 | 10 | <script src="../dist/gridstack-jq.js"></script> |
10 | 11 | <style type="text/css"> |
11 | 12 | .grid-stack .grid-stack { |
|
20 | 21 | <div class="container-fluid"> |
21 | 22 | <h1>Nested grids demo</h1> |
22 | 23 | <p>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)</p> |
23 | | - <p>Note: initial v3.0.0 HTML5 release doesn't support 'dragOut:false' constrain so this uses JQ version for now, otherwise recommend you use h5 version.</p> |
| 24 | + <p>Note: initial v3 HTML5 release doesn't support 'dragOut:false' constrain so this uses JQ version for now, otherwise recommend you use h5 version.</p> |
24 | 25 | <a class="btn btn-primary" onClick="addNewWidget('.nested1')" href="#">Add Widget Grid1</a> |
25 | 26 | <a class="btn btn-primary" onClick="addNewWidget('.nested2')" href="#">Add Widget Grid2</a> |
26 | 27 | <br><br> |
27 | 28 | <!-- grid will be added here --> |
28 | 29 | </div> |
29 | 30 |
|
30 | 31 | <script type="text/javascript"> |
31 | | - let sub1 = [ {w:3}, {w:3}, {w:3}, {w:3}, {w:3}, {w:3}]; |
32 | | - let sub2 = [ {w:3}, {x:0, y:1, w:3}]; |
| 32 | + 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}]; |
| 33 | + let sub2 = [ {x:0, y:0}, {x:0, y:1, w:2}]; |
33 | 34 | let count = 0; |
34 | 35 | [...sub1, ...sub2].forEach(d => d.content = String(count++)); |
35 | 36 | let subOptions = { |
| 37 | + cellHeight: 30, |
| 38 | + column: 4, // make sure to include gridstack-extra.min.css |
36 | 39 | itemClass: 'sub', // style sub items differently and use to prevent dragging in/out |
37 | 40 | acceptWidgets: '.grid-stack-item.sub', // only pink sub items can be inserted, otherwise grid-items causes all sort of issues |
38 | | - disableOneColumnMode: true, // nested are small, but still want N columns |
| 41 | + minWidth: 300, // min to go 1 column mode |
39 | 42 | margin: 1 |
40 | 43 | }; |
41 | | - let layout = {cellHeight: 70, children: [ |
42 | | - {w:1, content: 'regular item'}, |
| 44 | + let opts = {cellHeight: 70, children: [ |
| 45 | + {y:0, content: 'regular item'}, |
43 | 46 | {x:1, w:4, h:4, content: 'nested 1 - can drag items out', subGrid: {children: sub1, dragOut: true, class: 'nested1', ...subOptions}}, |
44 | 47 | {x:5, w:4, h:4, content: 'nested 2 - constrained to parent (default)', subGrid: {children: sub2, class: 'nested2', ...subOptions}}, |
45 | 48 | ]}; |
46 | 49 |
|
47 | 50 | // create and load it all from JSON above |
48 | | - GridStack.addGrid(document.querySelector('.container-fluid'), layout); |
| 51 | + GridStack.addGrid(document.querySelector('.container-fluid'), opts); |
49 | 52 |
|
50 | 53 | addNewWidget = function(selector) { |
51 | 54 | grid = document.querySelector(selector).gridstack; |
|
0 commit comments