This example demonstrates how to cancel editing or disable the editor conditionally for the grid when batch editing is in use. It is possible to execute your logic either on the client or server side for a complex business model.
Then, handle the grid's client-side BatchEditStartEditing event to either cancel the edit operation using the e.cancel property:
[JScript]if(condition) e.cancel = true;
or disable the editor by obtaining its client instance:
[JScript]var editor = s.GetEditor(e.focusedColumn.fieldName); editor.SetEnabled(condition);
The custom server-side logic can be executed in the CustomJSProperties event handler:
[C#]settings.CustomJSProperties+=(s,e)=>{varclientData=newDictionary<int,object>();vargrid=sasMVCxGridView;for(inti= 0;i<grid.VisibleRowCount;i++){varrowValues=grid.GetRowValues(i,newstring[]{"ID","ServerSideExample"})asobject[];varkey=Convert.ToInt32(rowValues[0]);if(key% 2 != 0)clientData.Add(key,"ServerSideExample");}e.Properties["cp_cellsToDisable"]=clientData;};
See Also:
ASPxGridView - Batch Editing - How to cancel editing or disable the editor conditionally
Question Comments
Added By: Mohan Sundaram 1 at: 11/17/2014 2:14:05 PM
This is great example for conditional disable/cancel of cells. I'm trying to do the same for Insert vs Update in batch edit mode. How do I differentiate if its Insert or Update. Basically, I have a primary key column which I do not want the user to change while updating and should be available for typing it in while Inserting.
Added By: Anthony (DevExpress Support) at: 11/18/2014 4:00:36 AMHi Mohan,
It is possible to check a visible index of the editing row. If the index is negative, the row will be inserted. Otherwise, it is an update operation.