简体   繁体   English

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

[英]Angular ag-Grid: how to refresh param value in custom cell renderer that is passed from the parent component?

I have my custom cell renderer for the editing menu:我有用于编辑菜单的自定义单元格渲染器:

在此处输入图像描述

To the renderer component I'm passing isEditing value, because when user click on Edit, then我将isEditing值传递给渲染器组件,因为当用户单击编辑时,然后

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

And in template:在模板中:

<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>

In my parent component where is the grid I have my column definition:在我的父组件中,网格在哪里,我有我的列定义:

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

The problem is I want to manage isEditing flag from the parent level.问题是我想从父级别管理isEditing标志。 But when I start row edition onClick then (rowEditingStarted) is triggered and I'm changing the flag:但是当我开始行版 onClick 然后(rowEditingStarted)被触发并且我正在更改标志:

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

As you can see, I tried to use refreshingCells method from gridApi but it doesn't help me.如您所见,我尝试使用refreshingCells中的 refreshCells 方法,但它对我没有帮助。 Maybe on of you have some idea to handle this?也许你们有一些想法来处理这个?

I tried using a similar method to what you implemented but could not get it to work.我尝试使用与您实现的方法类似的方法,但无法使其正常工作。 The value was not changing.价值没有改变。 Instead... I used a service which I subscribe to in the custom renderer.相反......我使用了我在自定义渲染器中订阅的服务。 In the parent component I have a button which toggles the "isEditing" variable and updates the value in the observable.在父组件中,我有一个按钮,用于切换“isEditing”变量并更新可观察对象中的值。

Parent Component父组件

this._TableRendererService.updateIsEdit(this.isEdit);

   

Custom Renderer自定义渲染器

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

make cell params value is a function like this:使单元格参数值为 function ,如下所示:

  cellRendererParams: {
    isEditing: () => this.isEditing
  }

and use it as a function:并将其用作 function:

 <div *ngIf="isEditing()"></div>

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

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