Skip to content

DevExpress-Examples/asp-net-mvc-grid-cancel-editing-conditionally-in-batch-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GridView for ASP.NET MVC - How to cancel editing conditionally in batch edit mode

You can cancel grid data editing in batch edit mode on the client or server side.

In this example, users can modify data only in even rows (except the ID column). Each column is protected in a different way, listed below.

Implementation Details

On the client, handle the BatchEditStartEditing event and set its e.cancel property to true to cancel editing:

function OnBatchStartEdit(s, e) {
  if (condition) e.cancel = true;
}

Another way to cancel editing is to use an editor's SetReadOnly method. The code sample below demonstrates how to disable an editor conditionally:

function OnBatchStartEdit(s, e) {
   if (condition) {
       editor = s.GetEditor(e.focusedColumn.fieldName);
       editor.SetReadOnly(true);
 }

You can implement custom server-side logic in the CustomJSProperties event handler:

settings.CustomJSProperties += (s, e) => {
    var clientData = new Dictionary<int,object>();
    var grid = s as MVCxGridView;
    for (int i = 0; i < grid.VisibleRowCount; i++) {
        var rowValues = grid.GetRowValues(i, new string[] {"ID", "ServerSideExample"}) as object[];

        var key = Convert.ToInt32(rowValues[0]);
        if (key % 2 != 0)
            clientData.Add(key, "ServerSideExample");
    }
    e.Properties["cp_cellsToDisable"] = clientData;
};

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Cancel grid data editing in batch edit mode on the client or server side.

Topics

Resources

License

Stars

Watchers

Forks

Languages