6

I am using ag-grid to display and modify data.How Can I switch between editable and non editable for the hole ag-grid. Can I do this with the grid api.

this is my default config:

this.defaultDefs = {           
    suppressMovable: true,     
    enableColResize: true,     
    editable: true,            
};     

Can I change editable dynamically?

Mohamed Amine Ouali
  • 575
  • 1
  • 8
  • 23

6 Answers6

17

editable can be either a boolean as you have it, or a function

If you use the function form you can determine on a cell by cell basis if you want the given cell to be editable

editable: function(params) {
   return true; // true/false based on params (or some other criteria) value
}
thirtydot
  • 224,678
  • 48
  • 389
  • 349
Sean Landsman
  • 7,033
  • 2
  • 29
  • 33
  • thx I will try this by the way does this function affect the column that are always not editable I have same column where I specify editable:false will this function affect them – Mohamed Amine Ouali Jul 27 '17 at 17:18
  • You can set editable by column too - this will override the setting on the defaultDefs – Sean Landsman Jul 27 '17 at 17:20
  • So if defaultDefs get a function or a Boolean it will always be override – Mohamed Amine Ouali Jul 27 '17 at 17:24
  • No, what i mean is that any setting on detaultCols can be overridin on a column by column basis. Set any default on defaultDefs (say to be not editable) then override on a column by column basis as appropriate. Note that the default setting for a column is for it to NOT be editable – Sean Landsman Jul 27 '17 at 17:26
1

you can set editable property by your way just create another function isEditable(columnName) which will give you boolean result.

this.defaultDefs = {           
    suppressMovable: true,     
    enableColResize: true,     
    editable: isEditable(column),            
};  
koolhuman
  • 1,581
  • 15
  • 25
0

Do a logic check in the cellEditingStarted callback, calling the stop() when the check fails. You may need to write some css to style it or add a toast/notification to give the user feedback on why they're not able to edit.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    One side-effect of this is that the edit interface will briefly flicker in between starting / canceling the edit, better to use a callback for the editable property, this way you can prevent entering edit mode at all on a cell-by-cell level if desired – blue18hutthutt Oct 01 '20 at 04:41
0

You can use it like this:

  1. editable: (params) => your logic
  2. update your date
  3. call api.redrawRows({ rowNodes: [node] })
0

You can also use suppressClickEdit in the grid options for a quick disabling:

gridOptions: {
   suppressClickEdit: true | false,
   ...
}

See: https://www.ag-grid.com/angular-data-grid/cell-editing-start-stop/#no-click-editing

ironmouse
  • 1,292
  • 2
  • 15
  • 23
0

A simpler approach

        editable: (params:any)=> params.data.isEdit === 'edit' ?  true :  false

add it to the columndefinitions

*

Note: isEdit === 'edit' is your custom logic

*