如何仅对ag网格中的某些行禁用编辑

L.E*_*L.E 4 angularjs ag-grid

我想根据条件只在我的ag-grid(exemple:2/5)中启用某些行。

editable:false不能帮上忙,因为除非有我不知道的方法,否则它将应用于整个列表

任何帮助请

un.*_*ike 6

您可以仅绑定function到中的editable属性columnDef,该属性将在每次尝试时执行edit

editable: this.checkEditFunction.bind(this)
...
checkEditFunction(params){
    //params.node - for row identity
    //params.column - for column identity
    return !params.node.isRowPinned() // - just as sample
}
Run Code Online (Sandbox Code Playgroud)

.bind(this) -仅用于外部功能


Par*_*osh 5

您可以在检查条件保持后调用stopEditing()的方法。gridApieditable: true

假设您正在编辑该行,

(rowEditingStarted)="onRowEditingStarted($event)"
Run Code Online (Sandbox Code Playgroud)

然后在您的组件中,您可以根据以下检查停止编辑。

private onRowEditingStarted($event) {
  if(!$event.data.propertyToCheck == <someCondition>) {
    this.gridApi.stopEditing();
}
Run Code Online (Sandbox Code Playgroud)

更新:

您必须更新编辑事件的模板。

<ag-grid-angular #agGrid
  ....
 (rowEditingStarted)="onRowEditingStarted($event)"
  ....
 ></ag-grid-angular>
</div>
Run Code Online (Sandbox Code Playgroud)

检查此示例以供参考:https://www.ag-grid.com/javascript-grid-cell-editing/#example-cell-editing