New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Determine insert or edit mode in RadGrid with Batch editing

DESCRIPTION

There are scenarios where it might be helpful to know whether the currently opened grid cell in Batch editing is from a new row or already existing one. Here are some samples:

  1. When you want your users to be able to insert but not to edit records, or vice versa.
  2. When you want to save user changes to database explicitly and want to determine whether they are coming from new or already existing row.
  3. When you want to prefill some values in insert mode depending on other field values.

SOLUTION

You can achieve this requirement using the approach demonstrated below. The provided snippet uses the following event handler for a sample:
OnBatchEditOpened.

Here is the logic:

<ClientSettings>
    <ClientEvents OnBatchEditOpened="batchEditOpened" />
</ClientSettings>
function batchEditOpened(sender, args) {
    args.get_tableView().get_dataItems();
    var item = args.get_row().control;
    if (item.get_itemIndex() < 0) { // new row
           // execute custom logic
    }
}
In this article
Not finding the help you need? Improve this article