簡體   English   中英

Angular ag-Grid:如何刷新從父組件傳遞的自定義單元格渲染器中的參數值?

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

我有用於編輯菜單的自定義單元格渲染器:

在此處輸入圖像描述

我將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});
}

如您所見,我嘗試使用refreshingCells中的 refreshCells 方法,但它對我沒有幫助。 也許你們有一些想法來處理這個?

我嘗試使用與您實現的方法類似的方法,但無法使其正常工作。 價值沒有改變。 相反......我使用了我在自定義渲染器中訂閱的服務。 在父組件中,我有一個按鈕,用於切換“isEditing”變量並更新可觀察對象中的值。

父組件

this._TableRendererService.updateIsEdit(this.isEdit);

   

自定義渲染器

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

使單元格參數值為 function ,如下所示:

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

並將其用作 function:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM