Skip to content

Commit 3aeef45

Browse files
authored
Merge pull request #2386 from akosfekete/sub-grid-update-issue
Do not remove subgrid when updating widget content
2 parents 23c1ebd + fd8bfd4 commit 3aeef45

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/gridstack.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,16 @@ export class GridStack {
11921192

11931193
// check for content changing
11941194
if (w.content) {
1195-
let sub = el.querySelector('.grid-stack-item-content');
1196-
if (sub && sub.innerHTML !== w.content) {
1197-
sub.innerHTML = w.content;
1195+
let toRemove = el.querySelectorAll('.grid-stack-item-content > :not(.grid-stack-nested, style)');
1196+
const subGrid = el.querySelector('.grid-stack-item-content > .grid-stack-nested')
1197+
const itemContent = el.querySelector('.grid-stack-item-content');
1198+
if (toRemove) {
1199+
toRemove.forEach(child => itemContent.removeChild(child));
11981200
}
1201+
const tempEl = document.createElement("div");
1202+
tempEl.innerHTML = w.content;
1203+
tempEl.childNodes.forEach(childNode => itemContent.insertBefore(childNode, subGrid));
1204+
11991205
delete w.content;
12001206
}
12011207

0 commit comments

Comments
 (0)