角ag-Grid:如何在自父组件传递的自定义单元格渲染器中刷新参数值?

时间:2020-06-14 21:36:38

标签: javascript angular ag-grid ag-grid-angular

我有用于编辑菜单的自定义单元格渲染器:

enter image description here

我要向渲染器组件传递isEditing值,因为当用户单击“编辑”时,然后

agInit(params: ICellRendererParams) {
 this.params = params;
 this.data = params.data;
 this.isEditing = this.params.isEditing;
}

在模板中:

<ng-container *ngIf="!isEditing">
HERE IS MENU ICON VIEW
</ng-container>
<div *ngIf="isEditing" class="d-flex justify-content-center align-items-center">
  <button type="button" class="btn btn-primary m-1" (click)="onSave()">{{'shared.save' | translate}} 
  </button>
  <button type="button" class="btn btn-secondary m-1" (click)="onCancel()">{{'shared.cancel' | translate}}</button>
</div>

在我的父组件中,网格在哪里,我有我的列定义:

  headerName: '',
  cellRendererFramework: EditRendererComponent,
  cellRendererParams: {
    isEditing: this.isEditing
  }

问题是我想从父级别管理isEditing标志。但是,当我开始行编辑onClick时,会触发(rowEditingStarted)并更改标志:

{
this.isEditing = true;
this.gridApi.refreshCells({force: true});
}

如您所见,我尝试使用gridApi中的refreshingCells方法,但对我没有帮助。也许您对解决这个问题有想法?

1 个答案:

答案 0 :(得分:0)

我尝试使用与您实施的方法类似的方法,但无法使其正常工作。价值没有改变。 反而... 我使用了我在自定义渲染器中订阅的服务。在父组件中,我有一个按钮可以切换“isEditing”变量并更新 observable 中的值。

<块引用>

父组件

this._TableRendererService.updateIsEdit(this.isEdit);

   
<块引用>

自定义渲染器

  agInit(params: any) {
    this.params = params;
    this._TableRendererService.currentIsEdit.subscribe(isEdit => this.isEdit = isEdit);
  }