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

ASPxGridView - 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:

[JavaScript]
if(condition) e.cancel = true;

 or disable the editor by obtaining its client instance:

[JavaScript]
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.

Added By: Anthony (DevExpress Support) at: 5/20/2015 8:37:56 AM    

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.

Added By: Nick Bohnet at: 7/27/2016 5:32:41 PM    Hi,
This works great!
I need to disable certain rows, not just certain editors, based on a condition in a hidden col.
I used the server method GetRowValues to get the hidden col value.  

How would I set the entire row on the client to readonly based on the value of this hidden column.
Or is there an alternative way to disable editing the grid row conditionally?

Thanks! Added By: Anthony (DevExpress Support) at: 7/28/2016 1:45:41 AM    

Hello,

I've created a separate ticket on your behalf (T408472: ASPxGridView - Batch Editing - How to disable certain rows). It has been placed in our processing queue and will be answered shortly.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>