Skip to content

Commit 3888748

Browse files
author
Alain Dumesny
committed
1 column edit propagation fixes
* re-order in 1 column no longer affect other layouts (hard to predict). only resize/add/remove carry over. * more fix #37 and part2 of #1120 * column.html demo has been updated to support item delete.
1 parent 77df15c commit 3888748

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

demo/column.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,21 @@ <h1>setColumn() grid demo</h1>
6363
];
6464
var count = 0;
6565
grid.batchUpdate();
66-
for (count=0; count<4;) {
67-
var n = items[count];
68-
grid.addWidget($('<div><div class="grid-stack-item-content">' + count++ + (n.text ? n.text : '') + '</div></div>'), n);
69-
};
66+
addWidget(); addWidget(); addWidget(); addWidget();
7067
grid.commit();
7168

72-
$('#add-widget').click(function() {
69+
function addWidget() {
7370
var n = items[count] || {
7471
x: Math.round(12 * Math.random()),
7572
y: Math.round(5 * Math.random()),
7673
width: Math.round(1 + 3 * Math.random()),
7774
height: Math.round(1 + 3 * Math.random())
7875
};
79-
grid.addWidget($('<div><div class="grid-stack-item-content">' + count++ + (n.text ? n.text : '') + '</div></div>'), n);
80-
});
76+
grid.addWidget($('<div><div class="grid-stack-item-content"><button onclick="grid.removeWidget(this.parentNode.parentNode)">X</button><br>'
77+
+ count++ + (n.text ? n.text : '') + '</div></div>'), n);
78+
};
8179

80+
$('#add-widget').click(function() { addWidget() });
8281
$('#1column').click(function() { delete grid.opts.oneColumnModeDomSort; grid.setColumn(1); $text.text(1);});
8382
$('#1columnDOM').click(function() { grid.opts.oneColumnModeDomSort = true; grid.setColumn(1); $text.text('1 DOM');});
8483
$('#2column').click(function() { grid.setColumn(2); $text.text(2);});

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Change log
3131

3232
- add `oneColumnModeDomSort` true|false to let you specify a custom layout (use dom order instead of x,y) for oneColumnMode `setColumn(1)` [#713](https://github.com/gridstack/gridstack.js/issues/713)
3333
- fix oneColumnMode to only restore if we auto went to it as window sizes up [#1125](https://github.com/gridstack/gridstack.js/pull/1125)
34+
- re-order in 1 column no longer affect other layouts (hard to predict). only resize/add/remove carry over [#1127](https://github.com/gridstack/gridstack.js/pull/1127)
3435

3536
## v0.6.1 (2020-02-02)
3637

src/gridstack.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,20 +1801,21 @@
18011801
GridStackEngine.prototype._layoutsNodesChange = function(nodes) {
18021802
if (!this._layouts || this._ignoreLayoutsNodeChange) return;
18031803
// remove smaller layouts - we will re-generate those on the fly... larger ones need to update
1804-
this._layouts.forEach(function(layout, i) {
1805-
if (!layout || i === this.column) return;
1806-
if (i < this.column) {
1807-
this._layouts[i] = undefined;
1804+
this._layouts.forEach(function(layout, column) {
1805+
if (!layout || column === this.column) return;
1806+
if (column < this.column) {
1807+
this._layouts[column] = undefined;
18081808
}
1809-
else {
1809+
// move in 1 column don't propagate (hard to do right thing). height are re-used and add/remove carry over
1810+
else if (this.column !== 1) {
18101811
// TODO: save the original x,y,w (h isn't cached) and see what actually changed to propagate correctly ?
18111812
nodes.forEach(function(node) {
18121813
var n = layout.find(function(l) { return l._id === node._id });
18131814
if (!n) return;
1814-
var ratio = i / this.column;
1815+
var ratio = column / this.column;
18151816
n.y = node.y;
18161817
n.x = Math.round(node.x * ratio);
1817-
// width ???
1818+
n.width = Math.round(node.width * ratio);
18181819
}, this);
18191820
}
18201821
}, this);

0 commit comments

Comments
 (0)