Skip to content

Commit 37acc2e

Browse files
authored
Merge pull request #2163 from adumesny/master
removing item from a grid (into another) will now call `change`
2 parents 13c28a8 + ae89921 commit 37acc2e

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

demo/events.js

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,56 @@ function addEvents(grid, id) {
55
let str = '';
66
items.forEach(function(item) { str += ' (' + item.x + ',' + item.y + ' ' + item.w + 'x' + item.h + ')'; });
77
console.log(g + event.type + ' ' + items.length + ' items (x,y w h):' + str );
8-
});
9-
10-
grid.on('enable', function(event) {
8+
})
9+
.on('enable', function(event) {
1110
let grid = event.target;
1211
console.log(g + 'enable');
13-
});
14-
15-
grid.on('disable', function(event) {
12+
})
13+
.on('disable', function(event) {
1614
let grid = event.target;
1715
console.log(g + 'disable');
18-
});
19-
20-
grid.on('dragstart', function(event, el) {
16+
})
17+
.on('dragstart', function(event, el) {
2118
let node = el.gridstackNode;
2219
let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same
2320
let y = el.getAttribute('gs-y');
2421
console.log(g + 'dragstart ' + el.textContent + ' pos: (' + node.x + ',' + node.y + ') = (' + x + ',' + y + ')');
25-
});
26-
27-
grid.on('drag', function(event, el) {
22+
})
23+
.on('drag', function(event, el) {
2824
let node = el.gridstackNode;
2925
let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same
3026
let y = el.getAttribute('gs-y');
3127
// console.log(g + 'drag ' + el.textContent + ' pos: (' + node.x + ',' + node.y + ') = (' + x + ',' + y + ')');
32-
});
33-
34-
grid.on('dragstop', function(event, el) {
28+
})
29+
.on('dragstop', function(event, el) {
3530
let node = el.gridstackNode;
3631
let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same
3732
let y = el.getAttribute('gs-y');
3833
console.log(g + 'dragstop ' + el.textContent + ' pos: (' + node.x + ',' + node.y + ') = (' + x + ',' + y + ')');
39-
});
40-
41-
grid.on('dropped', function(event, previousNode, newNode) {
34+
})
35+
.on('dropped', function(event, previousNode, newNode) {
4236
if (previousNode) {
4337
console.log(g + 'dropped - Removed widget from grid:', previousNode);
4438
}
4539
if (newNode) {
4640
console.log(g + 'dropped - Added widget in grid:', newNode);
4741
}
48-
});
49-
50-
grid.on('resizestart', function(event, el) {
42+
})
43+
.on('resizestart', function(event, el) {
5144
let n = el.gridstackNode;
5245
let w = parseInt(el.getAttribute('gs-w')); // verify node (easiest) and attr are the same
5346
let h = parseInt(el.getAttribute('gs-h'));
5447
if (w !== n.w || h !== n.h) alert('resizestart missmatch');
5548
let rec = el.getBoundingClientRect();
5649
console.log(`${g} resizestart ${el.textContent} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
5750

58-
});
59-
60-
grid.on('resize', function(event, el) {
51+
})
52+
.on('resize', function(event, el) {
6153
let n = el.gridstackNode;
6254
let rec = el.getBoundingClientRect();
6355
console.log(`${g} resize ${el.textContent} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
64-
});
65-
66-
grid.on('resizestop', function(event, el) {
56+
})
57+
.on('resizestop', function(event, el) {
6758
let n = el.gridstackNode;
6859
let w = parseInt(el.getAttribute('gs-w')); // verify node (easiest) and attr are the same
6960
let h = parseInt(el.getAttribute('gs-h'));

doc/CHANGES.md

Lines changed: 3 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+
- [7.2.0-dev (TBD)](#720-dev-tbd)
89
- [7.2.0 (2023-01-07)](#720-2023-01-07)
910
- [7.1.2 (2022-12-29)](#712-2022-12-29)
1011
- [7.1.1 (2022-11-13)](#711-2022-11-13)
@@ -77,6 +78,8 @@ Change log
7778
- [v0.1.0 (2014-11-18)](#v010-2014-11-18)
7879

7980
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
81+
## 7.2.0-dev (TBD)
82+
* fix [#2162](https://github.com/gridstack/gridstack.js/pull/2162) removing item from a grid (into another) will now call `change` if anything was also modified during the remove
8083

8184
## 7.2.0 (2023-01-07)
8285
* fix [#1936](https://github.com/gridstack/gridstack.js/issues/1936) some styles left behind after a drag

src/gridstack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,8 @@ export class GridStack {
19241924
if (wasAdded && origNode?.grid && origNode.grid !== this) {
19251925
let oGrid = origNode.grid;
19261926
oGrid.engine.removedNodes.push(origNode);
1927-
oGrid._triggerRemoveEvent();
1928-
// if it's an empty sub-grid, to get auto-created, nuke it
1927+
oGrid._triggerRemoveEvent()._triggerChangeEvent();
1928+
// if it's an empty sub-grid that got auto-created, nuke it
19291929
if (oGrid.parentGridItem && !oGrid.engine.nodes.length && oGrid.opts.subGridDynamic) {
19301930
oGrid.removeAsSubGrid();
19311931
}

0 commit comments

Comments
 (0)