6
6
< meta name ="viewport " content ="width=device-width, initial-scale=1 ">
7
7
< title > Advance Nested grids demo</ title >
8
8
< 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 -->
10
10
< script src ="../dist/gridstack-all.js "> </ script >
11
11
</ head >
12
12
< body >
13
13
< div class ="container-fluid ">
14
14
< 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
16
16
the new v7 API < code > GridStackOptions.subGrid.createDynamic=true</ code > </ p >
17
17
< 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 >
18
19
< 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 >
20
23
< span > entire save/re-create:</ span >
21
24
< a class ="btn btn-primary " onClick ="save() " href ="# "> Save</ a >
22
25
< a class ="btn btn-primary " onClick ="destroy() " href ="# "> Destroy</ a >
@@ -31,10 +34,11 @@ <h1>Advanced Nested grids demo</h1>
31
34
</ div >
32
35
33
36
< 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 } ] ;
35
39
let sub1 = [ { x :0 , y :0 } , { x :1 , y :0 } ] ;
36
40
let count = 0 ;
37
- [ ...main , ...sub1 ] . forEach ( d => d . content = String ( count ++ ) ) ;
41
+ [ ...main , ...sub0 , ... sub1 ] . forEach ( d => d . content = String ( count ++ ) ) ;
38
42
let subOptions = {
39
43
cellHeight : 50 , // should be 50 - top/bottom
40
44
column : 'auto' , // size to match container. make sure to include gridstack-extra.min.css
@@ -51,44 +55,46 @@ <h1>Advanced Nested grids demo</h1>
51
55
subGrid : subOptions ,
52
56
children : [
53
57
...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>"*/ },
55
61
]
56
62
} ;
57
63
58
64
// create and load it all from JSON above
59
65
let grid = GridStack . addGrid ( document . querySelector ( '.container-fluid' ) , options ) ;
60
66
61
- addNested = function ( ) {
67
+ function addNested ( ) {
62
68
grid . addWidget ( { x :0 , y :100 , content :"new item" } ) ;
63
69
}
64
70
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 ;
67
73
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()),
72
78
content : String ( count ++ )
73
79
} ;
74
80
subGrid . addWidget ( node ) ;
75
81
return false ;
76
82
} ;
77
83
78
- save = function ( content = true , full = true ) {
84
+ function save ( content = true , full = true ) {
79
85
options = grid . save ( content , full ) ;
80
86
console . log ( options ) ;
81
87
// console.log(JSON.stringify(options));
82
88
}
83
- destroy = function ( full = true ) {
89
+ function destroy ( full = true ) {
84
90
if ( full ) {
85
91
grid . destroy ( ) ;
86
92
grid = undefined ;
87
93
} else {
88
94
grid . removeAll ( ) ;
89
95
}
90
96
}
91
- load = function ( full = true ) {
97
+ function load ( full = true ) {
92
98
if ( full ) {
93
99
grid = GridStack . addGrid ( document . querySelector ( '.container-fluid' ) , options ) ;
94
100
} else {
0 commit comments