Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: applyHtmlCode util should always clear targeted native element #926

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,21 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e

/**
* Apply HTML code by 3 different ways depending on what is provided as input and what options are enabled.
* 1. value is an HTMLElement, then simply append the HTML to the target element.
* 1. value is an HTMLElement or DocumentFragment, then first empty the target and simply append the HTML to the target element.
* 2. value is string and `enableHtmlRendering` is enabled, then use `target.innerHTML = value;`
* 3. value is string and `enableHtmlRendering` is disabled, then use `target.textContent = value;`
* @param target - target element to apply to
* @param val - input value can be either a string or an HTMLElement
*/
applyHtmlCode(target: HTMLElement, val: string | HTMLElement | DocumentFragment) {
applyHtmlCode(target: HTMLElement, val: string | HTMLElement | DocumentFragment, emptyTarget = true) {
if (target) {
if (val instanceof HTMLElement || val instanceof DocumentFragment) {
// first empty target and then append new HTML element
if (emptyTarget) {
Utils.emptyElement(target);
}
target.appendChild(val);
} else if (typeof val === 'string') {
} else {
if (this._options.enableHtmlRendering) {
target.innerHTML = this.sanitizeHtmlString(val as string);
} else {
Expand Down