@@ -21,12 +21,8 @@ <h1>Nested grids demo</h1>
2121 < a class ="btn btn-primary " onClick ="addNewWidget('.sub1') " href ="# "> Add Widget Grid1</ a >
2222 < a class ="btn btn-primary " onClick ="addNewWidget('.sub2') " href ="# "> Add Widget Grid2</ a >
2323 < 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 >
3026 </ div >
3127 < br />
3228 < span > entire save/re-create:</ span >
@@ -78,7 +74,10 @@ <h1>Nested grids demo</h1>
7874 } )
7975
8076 // 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 ) ;
8281
8382 function addWidget ( ) {
8483 grid . addWidget ( { x :0 , y :100 , content :"new item" } ) ;
@@ -104,25 +103,6 @@ <h1>Nested grids demo</h1>
104103 return false ;
105104 } ;
106105
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-
126106 //--- end of Drag and Drop Nested widget logic
127107
128108 function save ( content = true , full = true ) {
@@ -142,7 +122,6 @@ <h1>Nested grids demo</h1>
142122 function load ( full = true ) {
143123 if ( full ) {
144124 grid = GridStack . addGrid ( document . querySelector ( '.container-fluid' ) , options ) ;
145- grid . on ( 'dropped' , droppedHandler ) ;
146125 } else {
147126 grid . load ( options ) ;
148127 }
0 commit comments