8

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

Paritosh
  • 11,144
  • 5
  • 56
  • 74
L.E
  • 83
  • 1
  • 1
  • 7

2 Answers2

19

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

un.spike
  • 4,857
  • 2
  • 18
  • 38
5

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

Paritosh
  • 11,144
  • 5
  • 56
  • 74
  • can you please tell me if we should declare it this way model.columns = [ {checkboxSelection: enableEdition, editable: true rowEditingStarted:onRowEditingStarted($event) }] – L.E May 16 '18 at 14:42
  • var onRowEditingStarted=function($event) { if($event.data.x === model.x) { this.gridApi.stopEditing(); } }; – L.E May 16 '18 at 14:43
  • I don't think i can do that beacuse i'm in angularJS 1.5 – L.E May 17 '18 at 10:28
  • Note: I needed to use `cellEditingStarted` instead of `rowEditingStarted` since I was not using _Full Row Editing_ – Marty131 Jul 02 '18 at 23:46