Skip to content

Commit 8a5adae

Browse files
committed
column-N class fix
* fix for #1572 * we now automatically add `.grid-stack-N` class when user specify column: N option for CSS to work.
1 parent 5d36e26 commit 8a5adae

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ GridStack.init( {column: N} );
179179
<div class="grid-stack grid-stack-N">...</div>
180180
```
181181

182-
Note: we added `.grid-stack-N` and include `gridstack-extra.css` which defines CSS for grids with custom [2-11] columns. Anything more and you'll need to generate the SASS/CSS yourself (see next).
182+
Note: class `.grid-stack-N` was added and we include `gridstack-extra.css` which defines CSS for grids with custom [2-11] columns. Anything more and you'll need to generate the SASS/CSS yourself (see next).
183183

184184
See example: [2 grids demo](http://gridstack.github.io/gridstack.js/demo/two.html) with 6 columns
185185

doc/CHANGES.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ Change log
4747
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
4848
## 3.1.4-dev
4949

50-
- TBD
50+
- fix [1572](https://github.com/gridstack/gridstack.js/issues/1572) `column: N` option now sets CSS class
51+
5152
## 3.1.4 (2021-1-11)
5253

53-
- fix [1557](https://github.com/gridstack/gridstack.js/pull/1557) fix no-drop cursor on windows when dragging within a default grid (no external drag in)
54-
- fix [1541](https://github.com/gridstack/gridstack.js/pull/1541) fix Safari H5 delay when dropping items
54+
- fix [1557](https://github.com/gridstack/gridstack.js/issues/1557) fix no-drop cursor on windows when dragging within a default grid (no external drag in)
55+
- fix [1541](https://github.com/gridstack/gridstack.js/issues/1541) fix Safari H5 delay when dropping items
5556

5657
## 3.1.3 (2021-1-2)
5758

spec/e2e/html/1572_one_column.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>1 column demo</title>
8+
9+
<link rel="stylesheet" href="../../../demo/demo.css"/>
10+
<script src="../../../dist/gridstack-h5.js"></script>
11+
<style type="text/css">
12+
.grid-stack {
13+
width: 200px;
14+
}
15+
</style>
16+
17+
</head>
18+
<body>
19+
<div class="container-fluid">
20+
<h1>1 column demo</h1>
21+
<div>
22+
<a class="btn btn-primary" onClick="addNewWidget()" href="#">Add Widget</a>
23+
<a class="btn btn-primary" onclick="toggleFloat()" id="float" href="#">float: true</a>
24+
</div>
25+
<br><br>
26+
<div class="grid-stack"></div>
27+
</div>
28+
<script src="../../../demo/events.js"></script>
29+
<script type="text/javascript">
30+
let count = 0;
31+
let items = [{x: 0, y: 0, w: 1, h:1, content: String(count++)}];
32+
33+
let grid = GridStack.init({column: 1});
34+
grid.load(items);
35+
addEvents(grid);
36+
37+
addNewWidget = function() {
38+
let n = items[count] || {
39+
x: Math.round(12 * Math.random()),
40+
y: Math.round(5 * Math.random()),
41+
w: Math.round(1 + 3 * Math.random()),
42+
h: Math.round(1 + 3 * Math.random()),
43+
content: String(count++)
44+
};
45+
grid.addWidget(n);
46+
};
47+
48+
toggleFloat = function() {
49+
grid.float(! grid.getFloat());
50+
document.querySelector('#float').innerHTML = 'float: ' + grid.getFloat();
51+
};
52+
</script>
53+
</body>
54+
</html>

src/gridstack.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ export class GridStack {
338338
this.placeholder.appendChild(placeholderChild);
339339

340340
this._updateStyles();
341+
if (this.opts.column != 12) {
342+
this.el.classList.add('grid-stack-' + this.opts.column);
343+
}
341344

342345
this._setupDragIn();
343346
this._setupRemoveDrop();

0 commit comments

Comments
 (0)