From 45d41347ba85a44cac43695c3fbc4050b8a3ccb0 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 27 Feb 2023 18:52:16 -0800 Subject: [PATCH] Adding null checks and fixing values in slickgrid checkbox column plugin (#22050) * Adding null checks to checkbox column * Setting default value for undefined checkbox --- .../ui/table/plugins/checkboxSelectColumn.plugin.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sql/base/browser/ui/table/plugins/checkboxSelectColumn.plugin.ts b/src/sql/base/browser/ui/table/plugins/checkboxSelectColumn.plugin.ts index de00cfe36c..4f27146a4e 100644 --- a/src/sql/base/browser/ui/table/plugins/checkboxSelectColumn.plugin.ts +++ b/src/sql/base/browser/ui/table/plugins/checkboxSelectColumn.plugin.ts @@ -60,7 +60,7 @@ export class CheckboxSelectColumn implements Slick.Pl private _handler = new Slick.EventHandler(); private _options: ICheckboxSelectColumnOptions; public index: number; - private _headerCheckbox: HTMLInputElement; + private _headerCheckbox: HTMLInputElement | undefined; private _onChange = new Emitter(); private _onCheckAllChange = new Emitter(); public readonly onChange: vsEvent = this._onChange.event; @@ -193,7 +193,9 @@ export class CheckboxSelectColumn implements Slick.Pl break; } } - this._headerCheckbox.checked = checked; + if (this._headerCheckbox) { + this._headerCheckbox.checked = checked; + } } public destroy(): void { @@ -217,12 +219,16 @@ export class CheckboxSelectColumn implements Slick.Pl const propertyValue = dataItem[this._options.title]; let checkboxEnabled: boolean = true; let checkboxChecked: boolean = false; + if (typeof propertyValue === 'boolean') { checkboxEnabled = true; checkboxChecked = propertyValue; } else if (propertyValue !== undefined) { checkboxEnabled = propertyValue.enabled === undefined ? true : propertyValue.enabled; checkboxChecked = propertyValue.checked === undefined ? false : propertyValue.checked; + } else if (propertyValue === undefined) { // If the value is undefined the checkbox will be enabled and unchecked + checkboxEnabled = true; + checkboxChecked = false; } return { @@ -234,7 +240,8 @@ export class CheckboxSelectColumn implements Slick.Pl private setCheckboxPropertyValue(row: number, value: boolean): void { const dataItem = this._grid?.getDataItem(row); const propertyValue = dataItem[this._options.title]; - if (typeof propertyValue === 'boolean') { + // If property value is undefined we treat the cell value as a boolean + if (propertyValue === undefined || typeof propertyValue === 'boolean') { (dataItem)[this._options.title] = value; } else { (dataItem)[this._options.title] = {