Skip to content

Commit 0a37462

Browse files
committed
new cellHeight:'fill' so rows divide the (fixed) grid height
* fix #2583 fix #787 * new cellHeight:'fill' so row numbers take entire fixed sized (by the application) grid height, which simulates cellHeight being %, but also aumatically adpate to always fill grid height. * update cell-height.html demo to show the new option
1 parent ea2827d commit 0a37462

8 files changed

Lines changed: 1013 additions & 890 deletions

File tree

‎angular/doc/api/gridstack.component.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ OnInit.ngOnInit
221221
ngAfterContentInit(): void;
222222
```
223223

224-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:272](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L272)
224+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:273](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L273)
225225

226226
wait until after all DOM is ready to init gridstack children (after angular ngFor and sub-components run first)
227227

@@ -241,7 +241,7 @@ AfterContentInit.ngAfterContentInit
241241
ngOnDestroy(): void;
242242
```
243243

244-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:280](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L280)
244+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:281](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L281)
245245

246246
A callback method that performs custom clean-up, invoked immediately
247247
before a directive, pipe, or service instance is destroyed.
@@ -262,7 +262,7 @@ OnDestroy.ngOnDestroy
262262
updateAll(): void;
263263
```
264264

265-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:294](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L294)
265+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:295](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L295)
266266

267267
called when the TEMPLATE (not recommended) list of items changes - get a list of nodes and
268268
update the layout accordingly (which will take care of adding/removing items changed by Angular)
@@ -277,7 +277,7 @@ update the layout accordingly (which will take care of adding/removing items cha
277277
checkEmpty(): void;
278278
```
279279

280-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:305](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L305)
280+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:306](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L306)
281281

282282
check if the grid is empty, if so show alternative content
283283

@@ -291,7 +291,7 @@ check if the grid is empty, if so show alternative content
291291
protected hookEvents(grid?): void;
292292
```
293293
294-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:311](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L311)
294+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:312](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L312)
295295
296296
get all known events as easy to use Outputs for convenience
297297
@@ -311,7 +311,7 @@ get all known events as easy to use Outputs for convenience
311311
protected unhookEvents(grid?): void;
312312
```
313313
314-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:338](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L338)
314+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:339](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L339)
315315
316316
###### Parameters
317317
@@ -3094,7 +3094,7 @@ function gsCreateNgComponents(
30943094
isGrid): undefined | HTMLElement;
30953095
```
30963096
3097-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:349](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L349)
3097+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:350](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L350)
30983098
30993099
can be used when a new item needs to be created, which we do as a Angular component, or deleted (skip)
31003100
@@ -3119,7 +3119,7 @@ can be used when a new item needs to be created, which we do as a Angular compon
31193119
function gsSaveAdditionalNgInfo(n, w): void;
31203120
```
31213121
3122-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:444](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L444)
3122+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:445](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L445)
31233123
31243124
called for each item in the grid - check if additional information needs to be saved.
31253125
Note: since this is options minus gridstack protected members using Utils.removeInternalForSave(),
@@ -3145,7 +3145,7 @@ using BaseWidget.serialize()
31453145
function gsUpdateNgComponents(n): void;
31463146
```
31473147
3148-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:463](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L463)
3148+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:464](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L464)
31493149
31503150
track when widgeta re updated (rather than created) to make sure we de-serialize them as well
31513151

‎demo/cell-height.html‎

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,46 @@
99
<link rel="stylesheet" href="demo.css"/>
1010
<script src="../dist/gridstack-all.js"></script>
1111
<style type="text/css">
12+
html, body {
13+
width: 100%;
14+
height: 100%;
15+
margin: 0;
16+
display: flex;
17+
}
1218
.container {
1319
background-color: lightblue;
1420
width: 100%;
15-
height: 800px;
21+
flex: 1;
22+
max-height: 800px; /* test grid not filling entire page */
23+
display: flex;
24+
flex-direction: column;
1625
}
1726
</style>
18-
1927
</head>
2028
<body>
2129
<div class="container">
2230
<h1>Cell Height grid options demo</h1>
23-
<p>sample showing the different cellHeight options and what happens when you resize the window</p>
31+
<p>sample showing the different cellHeight options and what happens when you resize the window<br>
32+
<b>New:</b> v14.x <i>cellHeight:'fill'</i> (rows divide the <b>grid height</b> which MUST be set by the app to something fixed as GS won't set a size)</p>
2433
<div>
2534
<a class="btn btn-primary" onClick="setOpt('auto')" href="#">auto</a>
2635
<a class="btn btn-primary" onClick="setOpt('initial')" href="#">initial</a>
2736
<a class="btn btn-primary" onClick="setOpt(100)" href="#">100px</a>
2837
<a class="btn btn-primary" onClick="setOpt('10vh')" href="#">'10vh'</a>
38+
<a class="btn btn-primary" onClick="setOpt('fill')" href="#">fill</a>
2939
<a class="btn btn-primary" onClick="setOpt('10%')" href="#">'10%' of blue (broken)</a>
3040
<span>settings:</span><span id="info"></span>
41+
<span>rows:</span><span id="rows"></span>
42+
<a class="btn btn-primary" onClick="grid.removeAll()" href="#">clear</a>
43+
</div>
44+
<br>
45+
<div class="sidebar" style="height: 40px">
46+
<div class="grid-stack-item">
47+
<div class="grid-stack-item-content">1x1</div>
48+
</div>
49+
<div class="grid-stack-item" gs-h="2">
50+
<div class="grid-stack-item-content">1x2</div>
51+
</div>
3152
</div>
3253
<br>
3354
<div class="grid-stack"></div>
@@ -36,21 +57,33 @@ <h1>Cell Height grid options demo</h1>
3657
let opts = {
3758
cellHeight: 'auto', // see other possible values (best to do in here)
3859
cellHeightThrottle: 100,
60+
acceptWidgets: true,
61+
children: [{x:0, y:0, content:'0'}, {x:1, y:0, w:2, content:'1'}, {x:3, y:0, h:2, content:'2'}]
3962
}
40-
let grid = GridStack.init(opts);
41-
let items = [
42-
{x:0, y:0, content:'0'},
43-
{x:1, y:0, w:2, content:'1'},
44-
{x:3, y:0, h:2, content:'2'},
45-
];
46-
grid.load(items);
4763

4864
let info = document.querySelector('#info');
49-
info.innerHTML = opts.cellHeight;
50-
setOpt = function(val) {
51-
grid.cellHeight(val);
65+
let rows = document.querySelector('#rows');
66+
let grid_el = document.querySelector('.grid-stack');
67+
setOpt = function(val, update = true) {
68+
if (val === 'fill') {
69+
grid_el.style.flex = '1';
70+
} else {
71+
grid_el.style.flex = 'none';
72+
}
73+
if (update && grid) grid.cellHeight(val);
5274
info.innerHTML = val;
5375
}
76+
77+
// initialize our CSS state BEFORE grid (reduces flicker)
78+
setOpt(opts.cellHeight, false);
79+
let grid = GridStack.init(opts);
80+
81+
GridStack.setupDragIn('.sidebar .grid-stack-item', { appendTo: 'body', helper: 'clone' });
82+
83+
grid.on('change added removed', function(e, items) {
84+
rows.innerHTML = grid.getRow();
85+
});
86+
rows.innerHTML = grid.getRow();
5487
</script>
5588
</body>
5689
</html>

0 commit comments

Comments
 (0)