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#]protectedvoidASPxGridView1_CustomJSProperties(objectsender,DevExpress.Web.ASPxGridView.ASPxGridViewClientJSPropertiesEventArgse){varclientData=newDictionary<int,object>();vargrid=senderasASPxGridView;for(inti=grid.VisibleStartIndex;i<grid.VisibleStartIndex+grid.SettingsPager.PageSize;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 - How to disable editing for rows that match some condition in Batch Edit Mode
GridView - Batch Editing - How to cancel editing or disable the editor conditionally
Question Comments
Added By: Phil George at: 5/20/2015 4:58:27 AM
Is there a better way to handle this? I have a grid with 700,000 rows which now loads really quickly using a linq datasource but when I add in the code to conditionally allow editing on rows which match a certain criteria, the load times are shocking as it looks at every row instead of the rows visible on the screen. And it does this when paging.
I have a boolean column which is returned which determines if the row is editable for the current user - how can I use this column to make my code more efficient.
Hello,
To process your recent post more efficiently, I created a separate ticket on your behalf: T244791: ASPxGridView - Batch Editing - How to cancel editing or disable the editor conditionally when Server mode is used. This ticket is currently in our processing queue. Our team will address it soon.