66 < meta name ="viewport " content ="width=device-width, initial-scale=1 ">
77 < title > Advance Nested grids demo</ title >
88 < link rel ="stylesheet " href ="demo.css "/>
9- < link rel ="stylesheet " href ="../dist/gridstack-extra.min.css "/>
9+ < link rel ="stylesheet " href ="../dist/gridstack-extra.min.css "/> <!-- required for [2-11] column of sub-grids -->
1010 < script src ="../dist/gridstack-all.js "> </ script >
1111</ head >
1212< body >
1313 < div class ="container-fluid ">
1414 < h1 > Advanced Nested grids demo</ h1 >
15- < p > Create sub-grids on the fly, by dragging items completely over others (nest) vs partially (push) using
15+ < p > Create sub-grids (darker background) on the fly, by dragging items completely over others (nest) vs partially (push) using
1616 the new v7 API < code > GridStackOptions.subGrid.createDynamic=true</ code > </ p >
1717 < p > This will use the new delay drag&drop option < code > DDDragOpt.pause</ code > to tell the gesture difference</ p >
18+ < p > Note: < code > gridstack-extra.min.css</ code > is required for [2-11] column of sub-grids</ p >
1819 < a class ="btn btn-primary " onClick ="addNested() " href ="# "> Add Widget</ a >
19- < a class ="btn btn-primary " onClick ="addNewWidget('sub1_grid') " href ="# "> Add Widget Grid1</ a >
20+ < a class ="btn btn-primary " onClick ="addNewWidget(0) " href ="# "> Add W Grid0</ a >
21+ < a class ="btn btn-primary " onClick ="addNewWidget(1) " href ="# "> Add W Grid1</ a >
22+ < a class ="btn btn-primary " onClick ="addNewWidget(2) " href ="# "> Add W Grid2</ a >
2023 < span > entire save/re-create:</ span >
2124 < a class ="btn btn-primary " onClick ="save() " href ="# "> Save</ a >
2225 < a class ="btn btn-primary " onClick ="destroy() " href ="# "> Destroy</ a >
@@ -31,10 +34,11 @@ <h1>Advanced Nested grids demo</h1>
3134 </ div >
3235
3336 < script type ="text/javascript ">
34- let main = [ { x :0 , y :0 } , { x :1 , y :0 } , { x :0 , y :1 } ]
37+ let main = [ { x :0 , y :0 } , { x :0 , y :1 } , { x :0 , y :2 } ]
38+ let sub0 = [ { x :0 , y :0 } ] ;
3539 let sub1 = [ { x :0 , y :0 } , { x :1 , y :0 } ] ;
3640 let count = 0 ;
37- [ ...main , ...sub1 ] . forEach ( d => d . content = String ( count ++ ) ) ;
41+ [ ...main , ...sub0 , ... sub1 ] . forEach ( d => d . content = String ( count ++ ) ) ;
3842 let subOptions = {
3943 cellHeight : 50 , // should be 50 - top/bottom
4044 column : 'auto' , // size to match container. make sure to include gridstack-extra.min.css
@@ -51,44 +55,46 @@ <h1>Advanced Nested grids demo</h1>
5155 subGrid : subOptions ,
5256 children : [
5357 ...main ,
54- { x :2 , y :0 , w :2 , h :3 , subGrid : { children : sub1 , id :'sub1_grid' , ...subOptions } /*,content: "<div>nested grid here</div>"*/ } ,
58+ { x :1 , y :2 , h :2 , subGrid : { children : sub0 , ...subOptions } } ,
59+ { x :2 , y :0 , w :2 , h :3 , subGrid : { children : sub1 , ...subOptions } } ,
60+ // {x:2, y:0, w:2, h:3, subGrid: {children: [...sub1, {x:0, y:1, subGrid: subOptions}], ...subOptions }/*,content: "<div>nested grid here</div>"*/ },
5561 ]
5662 } ;
5763
5864 // create and load it all from JSON above
5965 let grid = GridStack . addGrid ( document . querySelector ( '.container-fluid' ) , options ) ;
6066
61- addNested = function ( ) {
67+ function addNested ( ) {
6268 grid . addWidget ( { x :0 , y :100 , content :"new item" } ) ;
6369 }
6470
65- addNewWidget = function ( selector ) {
66- let subGrid = document . querySelector ( selector ) . gridstack ;
71+ function addNewWidget ( i ) {
72+ let subGrid = document . querySelectorAll ( '.grid-stack-nested' ) [ i ] . gridstack ;
6773 let node = {
68- x : Math . round ( 6 * Math . random ( ) ) ,
69- y : Math . round ( 5 * Math . random ( ) ) ,
70- w : Math . round ( 1 + 1 * Math . random ( ) ) ,
71- h : Math . round ( 1 + 1 * Math . random ( ) ) ,
74+ // x: Math.round(6 * Math.random()),
75+ // y: Math.round(5 * Math.random()),
76+ // w: Math.round(1 + 1 * Math.random()),
77+ // h: Math.round(1 + 1 * Math.random()),
7278 content : String ( count ++ )
7379 } ;
7480 subGrid . addWidget ( node ) ;
7581 return false ;
7682 } ;
7783
78- save = function ( content = true , full = true ) {
84+ function save ( content = true , full = true ) {
7985 options = grid . save ( content , full ) ;
8086 console . log ( options ) ;
8187 // console.log(JSON.stringify(options));
8288 }
83- destroy = function ( full = true ) {
89+ function destroy ( full = true ) {
8490 if ( full ) {
8591 grid . destroy ( ) ;
8692 grid = undefined ;
8793 } else {
8894 grid . removeAll ( ) ;
8995 }
9096 }
91- load = function ( full = true ) {
97+ function load ( full = true ) {
9298 if ( full ) {
9399 grid = GridStack . addGrid ( document . querySelector ( '.container-fluid' ) , options ) ;
94100 } else {
0 commit comments