You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
import {ICellEditorAngularComp} from 'ag-grid-angular';
|
|
import {AfterViewInit, Component, ElementRef, ViewChild} from '@angular/core';
|
|
import {ICellEditorParams} from 'ag-grid-community';
|
|
|
|
@Component({
|
|
selector: 'cell-editor-paragraph',
|
|
template: `<input #input [(ngModel)]="value" readonly (click)="onClick()">`,
|
|
styles: [
|
|
`input {
|
|
width: 100%;
|
|
border: 1px solid grey;
|
|
}`
|
|
],
|
|
})
|
|
export class BooleanEditorComponent implements ICellEditorAngularComp, AfterViewInit {
|
|
private params: ICellEditorParams;
|
|
public value: string;
|
|
|
|
protected trueValue = 'True';
|
|
protected falseValue = 'False';
|
|
protected emptyValue = '';
|
|
|
|
@ViewChild('input', {static: false}) input: ElementRef;
|
|
|
|
agInit(params: ICellEditorParams): void {
|
|
this.params = params;
|
|
this.value = this.params.value;
|
|
console.log('bool params', {params});
|
|
|
|
// @ts-ignore
|
|
const values = params.colDef.additionalData.labelType.split('_');
|
|
this.trueValue = values[0].charAt(0).toUpperCase() + values[0].slice(1);
|
|
this.falseValue = values[1].charAt(0).toUpperCase() + values[1].slice(1);
|
|
}
|
|
|
|
getValue(): any {
|
|
return this.value;
|
|
}
|
|
|
|
ngAfterViewInit(): void {
|
|
this.onClick();
|
|
}
|
|
|
|
onClick() {
|
|
if ( this.value === this.trueValue ) {
|
|
this.value = this.falseValue;
|
|
} else if ( this.value === this.falseValue ) {
|
|
this.value = this.emptyValue;
|
|
} else {
|
|
this.value = this.trueValue;
|
|
}
|
|
}
|
|
}
|