mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35: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 _options: ICheckboxSelectColumnOptions;
|
||||
public index: number;
|
||||
private _headerCheckbox: HTMLInputElement;
|
||||
private _headerCheckbox: HTMLInputElement | undefined;
|
||||
private _onChange = new Emitter<ICheckboxCellActionEventArgs>();
|
||||
private _onCheckAllChange = new Emitter<ICheckAllActionEventArgs>();
|
||||
public readonly onChange: vsEvent<ICheckboxCellActionEventArgs> = this._onChange.event;
|
||||
@@ -193,7 +193,9 @@ export class CheckboxSelectColumn<T extends Slick.SlickData> 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<T extends Slick.SlickData> 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<T extends Slick.SlickData> 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') {
|
||||
(<any>dataItem)[this._options.title] = value;
|
||||
} else {
|
||||
(<any>dataItem)[this._options.title] = {
|
||||
|
||||
Reference in New Issue
Block a user