|
23 | 23 | </style> |
24 | 24 | </head> |
25 | 25 | <body> |
| 26 | + <h3>show dragging into sub grid</h3> |
26 | 27 | <div class="row"> |
27 | 28 | <div class="col-md-2 d-none d-md-block"> |
28 | 29 | <div class="newWidget grid-stack-item"> |
|
37 | 38 | <div class="grid-stack-item-content"> |
38 | 39 | This nested grid accepts new widget with class "newWidget"<br/> |
39 | 40 | The parent grid also accepts new widget but with a different class 'otherWidgetType'<br/> |
40 | | - <div class="grid-stack nested"> |
41 | | - <div class="grid-stack-item sub" gs-x="0" gs-y="0" gs-w="3" gs-h="1"><div class="grid-stack-item-content">1</div></div> |
42 | | - <div class="grid-stack-item sub" gs-x="3" gs-y="0" gs-w="3" gs-h="1"><div class="grid-stack-item-content">2</div></div> |
43 | | - <div class="grid-stack-item sub" gs-x="6" gs-y="0" gs-w="3" gs-h="1"><div class="grid-stack-item-content">3</div></div> |
44 | | - <div class="grid-stack-item sub" gs-x="9" gs-y="0" gs-w="3" gs-h="1"><div class="grid-stack-item-content">4</div></div> |
45 | | - <div class="grid-stack-item sub" gs-x="0" gs-y="1" gs-w="3" gs-h="1"><div class="grid-stack-item-content">5</div></div> |
46 | | - <div class="grid-stack-item sub" gs-x="3" gs-y="1" gs-w="3" gs-h="1"><div class="grid-stack-item-content">6</div></div> |
47 | | - </div> |
48 | | - |
| 41 | + <div class="grid-stack nested"></div> |
49 | 42 | </div> |
50 | 43 | </div> |
51 | 44 | </div> |
|
54 | 47 |
|
55 | 48 | <script type="text/javascript"> |
56 | 49 | let grid = GridStack.init({ acceptWidgets: '.otherWidgetType' }, '.grid-stack.outer'); |
57 | | - let gridNest = GridStack.init({ acceptWidgets: '.newWidget' }, '.grid-stack.nested'); |
| 50 | + let gridNest = GridStack.init({ |
| 51 | + acceptWidgets: '.newWidget', |
| 52 | + dragIn: '.newWidget', // class that can be dragged from outside |
| 53 | + dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' }, // clone |
| 54 | + itemClass: 'sub', |
| 55 | + }, '.grid-stack.nested'); |
| 56 | + gridNest.load([ |
| 57 | + {x:0, y:0, w:3, content:'1'}, |
| 58 | + {x:3, y:0, w:3, content:'2'}, |
| 59 | + {x:6, y:0, w:3, content:'2'}, |
| 60 | + {x:9, y:0, w:3, content:'3'}, |
| 61 | + {x:0, y:1, w:3, content:'4'}, |
| 62 | + {x:3, y:1, w:3, content:'5'}, |
| 63 | + ]); |
58 | 64 |
|
59 | 65 | grid.on('added removed change', function(e, items) { |
60 | 66 | let str = ''; |
61 | 67 | items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; }); |
62 | 68 | console.log(e.type + ' ' + items.length + ' items:' + str ); |
63 | 69 | }); |
64 | | - |
65 | | - $('.newWidget').draggable({ |
66 | | - revert: 'invalid', |
67 | | - scroll: false, |
68 | | - appendTo: 'body', |
69 | | - helper: 'clone' |
70 | | - }); |
71 | 70 | </script> |
72 | 71 | </body> |
73 | 72 | </html> |
0 commit comments