how to disable editing for only some rows in ag grid

爷,独闯天下 提交于 2019-12-06 05:13:42

问题


i want to enable only some rows in my ag-grid(exemple :2/5) based on a condition .

editable:false can't help because it is applied on the whole list unless if there is a method I do not know

any help please


回答1:


You can just bind function to editable property in columnDef, which will be executed on each try of 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
}

.bind(this) - just for accessibility of external functions




回答2:


You can call stopEditing() method of gridApi after checking the condition - keeping editable: true.

Suppose, you are editing the row,

(rowEditingStarted)="onRowEditingStarted($event)"

Then in your component, you can stop the editing based on a check as per below.

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

Update:

You'll have to update template for the editing event.

<ag-grid-angular #agGrid
  ....
 (rowEditingStarted)="onRowEditingStarted($event)"
  ....
 ></ag-grid-angular>
</div>

Check this example for reference: https://www.ag-grid.com/javascript-grid-cell-editing/#example-cell-editing



来源:https://stackoverflow.com/questions/50274212/how-to-disable-editing-for-only-some-rows-in-ag-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!