简体   繁体   English

带有角度复选框更改的ag-grid无法在模型中更新

[英]ag-grid with angular checkbox change not getting updated in model

I am using ag grid community version with angular 6. I have a single character (Y/N) as one of the attribute in json response. 我正在使用角度为6的ag网格社区版本。我有一个字符(Y / N)作为json响应中的属性之一。 I am able to display the checked value in UI 我可以在用户界面中显示选中的值

cellRenderer: params => {
    return `<input type='checkbox' ${params.value == 'Y' ? 'checked' : ''} />`;
}

When I change the value in UI the rowData is not getting updated. 当我更改UI中的值时,rowData不会更新。 I tried to (change)="onChange($event)" but does not seem to work. 我试图(change)=“ onChange($ event)”,但似乎不起作用。 Do I need to write a custom Cell Rendered and call some ag grid api to register the change? 我是否需要编写自定义的“单元格渲染”并调用一些Ag Grid API来注册更改?

Any code sample will be much appreciated. 任何代码示例将不胜感激。

Thanks 谢谢

this worked for me 这对我有用

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

    import {ICellRendererAngularComp} from "ag-grid-angular";

    @Component({
      selector: 'checkbox-cell',
      template: `<input type='checkbox' [checked]="params.value == 'Y' ? true : false" (click)="checkedVal()">`
    })
    export class CheckboxComponentRenderer implements ICellRendererAngularComp {
      public params: any;

      agInit(params: any): void {
        this.params = params;
      }

      public checkedVal() {
        console.log(this.params.node.data);
        this.params.value = this.params.value == 'Y' ? 'N' : 'Y';
        this.params.node.data.valid = this.params.value;
        console.log('checkVal - ' + this.params.value);
      }

      refresh(): boolean {
        console.log('in refresh');
        return false;
      }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM