#55 - add checkbox support to database boolean column type
This commit is contained in:
parent
bd69f0814d
commit
c4e641545c
@ -84,6 +84,7 @@
|
|||||||
<ion-select-option value="true_false">True/False</ion-select-option>
|
<ion-select-option value="true_false">True/False</ion-select-option>
|
||||||
<ion-select-option value="yes_no">Yes/No</ion-select-option>
|
<ion-select-option value="yes_no">Yes/No</ion-select-option>
|
||||||
<ion-select-option value="1_0">1/0</ion-select-option>
|
<ion-select-option value="1_0">1/0</ion-select-option>
|
||||||
|
<ion-select-option value="checkbox">Checkbox</ion-select-option>
|
||||||
</ion-select>
|
</ion-select>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</ion-col>
|
</ion-col>
|
||||||
|
@ -1,25 +1,45 @@
|
|||||||
import {ICellRendererAngularComp} from 'ag-grid-angular';
|
import {ICellRendererAngularComp} from 'ag-grid-angular';
|
||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {ICellRendererParams} from 'ag-grid-community';
|
import {ICellRendererParams} from 'ag-grid-community';
|
||||||
import * as moment from 'moment';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'editor-boolean-renderer',
|
selector: 'editor-boolean-renderer',
|
||||||
template: `{{ display }}`,
|
template: `
|
||||||
|
<ng-container *ngIf="!checkbox">{{ display }}</ng-container>
|
||||||
|
<div *ngIf="checkbox" style="width: 100%; text-align: center; padding-top: 3px;">
|
||||||
|
<ion-checkbox [checked]="params.value" (ionChange)="onChecked($event)"></ion-checkbox>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
styles: [`
|
||||||
|
:host {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
`],
|
||||||
})
|
})
|
||||||
export class BooleanRendererComponent implements ICellRendererAngularComp {
|
export class BooleanRendererComponent implements ICellRendererAngularComp {
|
||||||
public params: ICellRendererParams;
|
public params: ICellRendererParams;
|
||||||
public emptyValue = '';
|
public emptyValue = '';
|
||||||
public trueValue = 'True';
|
public trueValue = 'True';
|
||||||
public falseValue = 'False';
|
public falseValue = 'False';
|
||||||
|
public checkbox = false;
|
||||||
|
|
||||||
|
public checked = false;
|
||||||
|
|
||||||
agInit(params: ICellRendererParams): void {
|
agInit(params: ICellRendererParams): void {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
this.checkbox = params.colDef.additionalData.labelType === 'checkbox';
|
||||||
|
|
||||||
|
if ( !this.checkbox ) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const labelType = params.colDef.additionalData.labelType.split('_').map(x => x.charAt(0).toUpperCase() + x.slice(1));
|
const labelType = params.colDef.additionalData.labelType.split('_').map(x => x.charAt(0).toUpperCase() + x.slice(1));
|
||||||
this.trueValue = labelType[0];
|
this.trueValue = labelType[0];
|
||||||
this.falseValue = labelType[1];
|
this.falseValue = labelType[1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public get display() {
|
public get display() {
|
||||||
if ( this.params.value === true ) {
|
if ( this.params.value === true ) {
|
||||||
@ -34,4 +54,10 @@ export class BooleanRendererComponent implements ICellRendererAngularComp {
|
|||||||
refresh(params: any): boolean {
|
refresh(params: any): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onChecked($event) {
|
||||||
|
const checked = !this.params.value;
|
||||||
|
const colId = this.params.column.getColId();
|
||||||
|
this.params.node.setDataValue(colId, checked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user