New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

How to Disable Particular Cell or Particular Row in RadGrid BatchEditing

Environment

Product Version2019.3.1023
ProductRadGrid for ASP.NET AJAX

Description

Batch editing is a powerful editing mode in RadGrid. Although, it is necessary to restrict some user editing in Batch Editing. For example, disabling editing for existing rows or a specific column my be sometimes necessary.

The below GIF displays the user experience when adding multiple rows and disabling editing of existing items.

Disabling Editing by Row or Column

Solution

Use the provided OnBatchEditOpening Client-side API and a little custom logic to create the solution. See the below steps and code snippet for more details.

General Steps

  1. Get the master table view from the sender parameter.
  2. Get all the data items from the master table view.
  3. Iterate the data items.
  4. During iteration, only cancel existing items with an index greater than or equal to 0. New items will always have an item index 0f -1
  5. Confirm the item is the item being edited by comparing the data item id with the args parameter id.
  6. Optionally, if the goal is to disable editing for a specific column use the get_columnUniqueName args method to select the specifc column.
  7. Finally, cancel the edit.

Code snippet

JavaScript
function OnBatchEditOpening(sender, args) {
    var masterTableView = sender.get_masterTableView();
    var dataitems = masterTableView.get_dataItems();
    for (var i = 0; i < dataitems.length; i++) {
        if (dataitems[i]._itemIndex >= 0) {
            if (dataitems[i].get_id() === args.get_row().id) {
                if (args.get_columnUniqueName() === "ProductName") {
                    args.set_cancel(true);
                }
            }
        }
    }
}

See Also