New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
How to Disable Particular Cell or Particular Row in RadGrid BatchEditing
Environment
Product Version | 2019.3.1023 |
Product | RadGrid 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.
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
- Get the master table view from the sender parameter.
- Get all the data items from the master table view.
- Iterate the data items.
- 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
- Confirm the item is the item being edited by comparing the data item id with the args parameter id.
- Optionally, if the goal is to disable editing for a specific column use the get_columnUniqueName args method to select the specifc column.
- 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);
}
}
}
}
}