@@ -21,12 +21,8 @@ <h1>Nested grids demo</h1>
21
21
< a class ="btn btn-primary " onClick ="addNewWidget('.sub1') " href ="# "> Add Widget Grid1</ a >
22
22
< a class ="btn btn-primary " onClick ="addNewWidget('.sub2') " href ="# "> Add Widget Grid2</ a >
23
23
< a class ="btn btn-primary " onClick ="addNested() " href ="# "> Add Nested Grid</ a >
24
- < div class ="sidebar " style ="height:50px; padding: 0 ">
25
- <!-- manually force a drop size of 2x2 for nested size -->
26
- < div class ="grid-stack-item " gs-w ="2 " gs-h ="2 ">
27
- < div class ="grid-stack-item-content "> Drag nested</ div >
28
- </ div >
29
- </ div >
24
+ <!-- add .grid-stack-item for acceptWidgets:true -->
25
+ < div class ="sidebar-item grid-stack-item "> Drag nested</ div >
30
26
</ div >
31
27
< br />
32
28
< span > entire save/re-create:</ span >
@@ -78,7 +74,10 @@ <h1>Nested grids demo</h1>
78
74
} )
79
75
80
76
// setup drag drop behavior
81
- GridStack . setupDragIn ( '.sidebar .grid-stack-item' , { appendTo : 'body' , helper : 'clone' } ) ;
77
+ let sidebarContent = [
78
+ { w :2 , h :2 , subGridOpts : { children : [ { content : 'nest 1' } , { content : 'nest 2' } ] } }
79
+ ] ;
80
+ GridStack . setupDragIn ( '.sidebar-item' , undefined , sidebarContent ) ;
82
81
83
82
function addWidget ( ) {
84
83
grid . addWidget ( { x :0 , y :100 , content :"new item" } ) ;
@@ -104,25 +103,6 @@ <h1>Nested grids demo</h1>
104
103
return false ;
105
104
} ;
106
105
107
- // listener on drop event: every time the sidebar item is dropped create a new subgrid
108
- function droppedHandler ( event , prevNode , n ) {
109
- // if we don't have a prevNode that means it came from toolbar, which today is the only nested case (else check for some node.el.getAttribute or some custom field...)
110
- if ( prevNode ) return ;
111
-
112
- // clear the content then make it a subgrid
113
- n . el . querySelector ( '.grid-stack-item-content' ) . innerHTML = '' ;
114
- let nodeToAdd = { children : [ { content : 'nest 1' } , { content : 'nest 2' } ] } ;
115
- let subgrid = n . grid . makeSubGrid ( n . el , nodeToAdd , undefined , false ) ;
116
-
117
- // add a listener to the subgrid to allow widgets to be added into this newly created nested widget
118
- subgrid . on ( 'dropped' , droppedHandler ) ;
119
- }
120
- // add listener to the main grid and subgrids
121
- grid . on ( 'dropped' , droppedHandler ) ;
122
- document . querySelectorAll ( '.grid-stack-nested' ) . forEach ( ( subGrid ) => {
123
- subGrid . gridstack . on ( 'dropped' , droppedHandler ) ;
124
- } ) ;
125
-
126
106
//--- end of Drag and Drop Nested widget logic
127
107
128
108
function save ( content = true , full = true ) {
@@ -142,7 +122,6 @@ <h1>Nested grids demo</h1>
142
122
function load ( full = true ) {
143
123
if ( full ) {
144
124
grid = GridStack . addGrid ( document . querySelector ( '.container-fluid' ) , options ) ;
145
- grid . on ( 'dropped' , droppedHandler ) ;
146
125
} else {
147
126
grid . load ( options ) ;
148
127
}
0 commit comments