mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Adding null checks and fixing values in slickgrid checkbox column plugin (#22050)
* Adding null checks to checkbox column * Setting default value for undefined checkbox
This commit is contained in:
@@ -60,7 +60,7 @@ export class CheckboxSelectColumn<T extends Slick.SlickData> implements Slick.Pl
|
|||||||
private _handler = new Slick.EventHandler();
|
private _handler = new Slick.EventHandler();
|
||||||
private _options: ICheckboxSelectColumnOptions;
|
private _options: ICheckboxSelectColumnOptions;
|
||||||
public index: number;
|
public index: number;
|
||||||
private _headerCheckbox: HTMLInputElement;
|
private _headerCheckbox: HTMLInputElement | undefined;
|
||||||
private _onChange = new Emitter<ICheckboxCellActionEventArgs>();
|
private _onChange = new Emitter<ICheckboxCellActionEventArgs>();
|
||||||
private _onCheckAllChange = new Emitter<ICheckAllActionEventArgs>();
|
private _onCheckAllChange = new Emitter<ICheckAllActionEventArgs>();
|
||||||
public readonly onChange: vsEvent<ICheckboxCellActionEventArgs> = this._onChange.event;
|
public readonly onChange: vsEvent<ICheckboxCellActionEventArgs> = this._onChange.event;
|
||||||
@@ -193,7 +193,9 @@ export class CheckboxSelectColumn<T extends Slick.SlickData> implements Slick.Pl
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._headerCheckbox.checked = checked;
|
if (this._headerCheckbox) {
|
||||||
|
this._headerCheckbox.checked = checked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy(): void {
|
public destroy(): void {
|
||||||
@@ -217,12 +219,16 @@ export class CheckboxSelectColumn<T extends Slick.SlickData> implements Slick.Pl
|
|||||||
const propertyValue = dataItem[this._options.title];
|
const propertyValue = dataItem[this._options.title];
|
||||||
let checkboxEnabled: boolean = true;
|
let checkboxEnabled: boolean = true;
|
||||||
let checkboxChecked: boolean = false;
|
let checkboxChecked: boolean = false;
|
||||||
|
|
||||||
if (typeof propertyValue === 'boolean') {
|
if (typeof propertyValue === 'boolean') {
|
||||||
checkboxEnabled = true;
|
checkboxEnabled = true;
|
||||||
checkboxChecked = propertyValue;
|
checkboxChecked = propertyValue;
|
||||||
} else if (propertyValue !== undefined) {
|
} else if (propertyValue !== undefined) {
|
||||||
checkboxEnabled = propertyValue.enabled === undefined ? true : propertyValue.enabled;
|
checkboxEnabled = propertyValue.enabled === undefined ? true : propertyValue.enabled;
|
||||||
checkboxChecked = propertyValue.checked === undefined ? false : propertyValue.checked;
|
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 {
|
return {
|
||||||
@@ -234,7 +240,8 @@ export class CheckboxSelectColumn<T extends Slick.SlickData> implements Slick.Pl
|
|||||||
private setCheckboxPropertyValue(row: number, value: boolean): void {
|
private setCheckboxPropertyValue(row: number, value: boolean): void {
|
||||||
const dataItem = this._grid?.getDataItem(row);
|
const dataItem = this._grid?.getDataItem(row);
|
||||||
const propertyValue = dataItem[this._options.title];
|
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') {
|
||||||
(<any>dataItem)[this._options.title] = value;
|
(<any>dataItem)[this._options.title] = value;
|
||||||
} else {
|
} else {
|
||||||
(<any>dataItem)[this._options.title] = {
|
(<any>dataItem)[this._options.title] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user