Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 135f919

Browse files
authored
Merge pull request #2878 from adumesny/master
sub-grid inherit parent opts by default
2 parents a987916 + 5cabee9 commit 135f919

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

demo/demo.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ h1 {
4444
.grid-stack {
4545
background: #FAFAD2;
4646
}
47+
.grid-stack.grid-stack-static {
48+
background: #eee;
49+
}
4750

4851
.sidebar > .grid-stack-item,
4952
.grid-stack-item-content {
5053
text-align: center;
5154
background-color: #18bc9c;
5255
}
56+
.ui-draggable-disabled.ui-resizable-disabled > .grid-stack-item-content {
57+
background-color: #777;
58+
}
5359

5460
.grid-stack-item-removing {
5561
opacity: 0.5;

demo/nested.html

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ <h1>Nested grids demo</h1>
2525
<div class="sidebar-item grid-stack-item">Drag nested</div>
2626
</div>
2727
<br />
28+
<div>
29+
<span>Grid Mode: </span>
30+
<input type="radio" id="static" name="mode" value="true" onClick="setStatic(true)"><label for="static">static</label>
31+
  <input type="radio" id="edit" name="mode" value="false" checked onClick="setStatic(false)"><label for="edit">editable</label>
32+
</div>
2833
<span>entire save/re-create:</span>
2934
<a class="btn btn-primary" onClick="save()" href="#">Save</a>
3035
<a class="btn btn-primary" onClick="destroy()" href="#">Destroy</a>
@@ -39,17 +44,19 @@ <h1>Nested grids demo</h1>
3944
</div>
4045
<script src="events.js"></script>
4146
<script type="text/javascript">
47+
let staticGrid = false;
4248
let sub1 = [ {x:0, y:0}, {x:1, y:0}, {x:2, y:0}, {x:3, y:0}, {x:0, y:1}, {x:1, y:1}];
4349
let sub2 = [ {x:0, y:0, h:2}, {x:1, y:1, w:2}];
4450
let count = 0;
4551
[...sub1, ...sub2].forEach(d => d.content = String(count++));
4652
let subOptions = {
47-
cellHeight: 50, // should be 50 - top/bottom
48-
column: 'auto', // size to match container. make sure to include gridstack-extra.min.css
49-
acceptWidgets: true, // will accept .grid-stack-item by default
50-
margin: 5,
53+
// by default we inherit from parent, but you can override any sub-grid options here
54+
// column: 'auto', // DEFAULT size to match container. make sure to include gridstack-extra.min.css
5155
};
5256
let options = { // main grid options
57+
staticGrid, // test - force children to inherit too if we set to true above ^^^
58+
// disableDrag: true,
59+
// disableResize: true,
5360
cellHeight: 50,
5461
margin: 5,
5562
minRow: 2, // don't collapse when empty
@@ -80,6 +87,11 @@ <h1>Nested grids demo</h1>
8087
];
8188
GridStack.setupDragIn('.sidebar-item', undefined, sidebarContent);
8289

90+
function setStatic(val) {
91+
staticGrid = val;
92+
grid.setStatic(staticGrid);
93+
}
94+
8395
function addWidget() {
8496
grid.addWidget({x:0, y:100, content:"new item"});
8597
}

doc/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [11.1.0-dev (TBD)](#1110-dev-tbd)
89
- [11.1.0 (2024-11-17)](#1110-2024-11-17)
910
- [11.0.1 (2024-10-21)](#1101-2024-10-21)
1011
- [11.0.0 (2024-10-20)](#1100-2024-10-20)
@@ -116,6 +117,9 @@ Change log
116117

117118
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
118119

120+
## 11.1.0-dev (TBD)
121+
* fix: [#2877](https://github.com/gridstack/gridstack.js/pull/2877) make sure sub-grid inherit parent opts by default, with subgrid defaults.
122+
119123
## 11.1.0 (2024-11-17)
120124
* feat: [#2864](https://github.com/gridstack/gridstack.js/issues/2864) added `GridStackOptions.layout` for nested grid reflow during resize. default to 'list'.
121125
* fix: [#2859](https://github.com/gridstack/gridstack.js/pull/2859) re-enabled tests and fix numerous issues found (see CL). Also thank you [lmartorella](https://github.com/lmartorella) for getting me going and starting it.

src/gridstack.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,12 @@ export class GridStack {
518518
grid = grid.parentGridNode?.grid;
519519
}
520520
//... and set the create options
521-
ops = Utils.cloneDeep({ ...(subGridTemplate || {}), children: undefined, ...(ops || node.subGridOpts || {}) });
521+
ops = Utils.cloneDeep({
522+
// by default sub-grid inherit from us | parent, other than id, children, etc...
523+
...this.opts, id: undefined, children: undefined, column: 'auto', columnOpts: undefined, layout: 'list', subGridOpts: undefined,
524+
...(subGridTemplate || {}),
525+
...(ops || node.subGridOpts || {})
526+
});
522527
node.subGridOpts = ops;
523528

524529
// if column special case it set, remember that flag and set default

0 commit comments

Comments
 (0)