Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

GridView - Batch Editing - How to cancel editing or disable the editor conditionally

$
0
0

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 AM    

Hi 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.

Added By: Rajeev Raysad at: 7/15/2015 11:10:33 PM    

I need to know how can I set one row to not editable!! I want other rows to be editable!!

Added By: Anthony (DevExpress Support) at: 7/16/2015 2:45:03 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T267677: GridView - Batch Editing - How to cancel editing a certain row. This ticket is currently in our processing queue. Our team will address it soon.


Viewing all articles
Browse latest Browse all 7205

Trending Articles