Skip to content

Commit 15a590b

Browse files
authored
fix(core): col name from HTML shouldn't disappear in picker, fixes #1475 (#1476)
- when unselecting any column from ColumnPicker/GridMenu it was causing columns created from native HTML element to disappear, I'm not exactly sure why but it looks like if I clone the node before calling `.appendChild` then the problem no longer exists. For reference, the issue is from these lines https://github.com/ghiscoding/slickgrid-universal/blob/185b6f9e44400bec2f1d79568905ca79e4b338a5/packages/common/src/core/slickGrid.ts#L1615-L1616
1 parent 185b6f9 commit 15a590b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/common/src/core/slickGrid.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,16 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
571571
* `sanitizerOptions` is to provide extra options when using `innerHTML` and the sanitizer.
572572
* `skipEmptyReassignment`, defaults to true, when enabled it will not try to reapply an empty value when the target is already empty
573573
*/
574-
applyHtmlCode(target: HTMLElement, val: string | boolean | number | HTMLElement | DocumentFragment = '', options?: { emptyTarget?: boolean; sanitizerOptions?: unknown; skipEmptyReassignment?: boolean; }) {
574+
applyHtmlCode(target: HTMLElement, val: string | boolean | number | HTMLElement | DocumentFragment = '', options?: { emptyTarget?: boolean; sanitizerOptions?: unknown; skipEmptyReassignment?: boolean; cloneNode?: boolean; }) {
575575
if (target) {
576576
if (val instanceof HTMLElement || val instanceof DocumentFragment) {
577577
// first empty target and then append new HTML element
578578
const emptyTarget = options?.emptyTarget !== false;
579579
if (emptyTarget) {
580580
emptyElement(target);
581581
}
582-
target.appendChild(val);
582+
const node = options?.cloneNode ? val.cloneNode(true) : val;
583+
target.appendChild(node);
583584
} else {
584585
// when it's already empty and we try to reassign empty, it's probably ok to skip the assignment
585586
const skipEmptyReassignment = options?.skipEmptyReassignment !== false;
@@ -1613,7 +1614,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
16131614
header.classList.add(this._options.unorderableColumnCssClass!);
16141615
}
16151616
const colNameElm = createDomElement('span', { className: 'slick-column-name' }, header);
1616-
this.applyHtmlCode(colNameElm, m.name as string);
1617+
this.applyHtmlCode(colNameElm, m.name, { cloneNode: true });
16171618

16181619
Utils.width(header, m.width! - this.headerColumnWidthDiff);
16191620

0 commit comments

Comments
 (0)