列视图中的角度4 ng2-smart-table复选框

时间:2017-10-19 12:45:31

标签: angular ng2-smart-table

import { Component } from '@angular/core';

import { DefaultEditor } from 'ng2-smart-table';

@Component({
    selector: 'checkbox-editor',
    //styleUrls: ['./editor.component.scss'],
    template: `
    <input [ngClass]="inputClass"
           type="checkbox"
           class="form-control"
           [name]="cell.getId()"
           [checked]="cell.getValue() == (cell.getColumn().getConfig()?.true || true)"
           (click)="onClick.emit($event)"
           (change)="onChange($event)">
    `,
})
export class RenderCheckboxComponent extends DefaultEditor {
    //CheckboxEditorComponent
    constructor() {
        super();
    }

    onChange(event: any): void {
        const trueVal = (this.cell.getColumn().getConfig() && this.cell.getColumn().getConfig().true) || true;
        const falseVal = (this.cell.getColumn().getConfig() && this.cell.getColumn().getConfig().false) || false;
        this.cell.newValue = event.target.checked ? trueVal : falseVal;
    }
}

“单元格”不在自定义视图

1 个答案:

答案 0 :(得分:0)

我想您忘了在自定义编辑器组件中导入它。如果在自定义编辑器中需要Cell,则需要导入它。所以像这样添加它

import { DefaultEditor,Cell } from 'ng2-smart-table';

现在,您可以访问自定义组件中的单元格值。

this.cell.getValue() //now you can access cell value