Search code examples
teleriktelerik-gridtelerik-mvc

How to determine if a grid row is new on edit in a Telerik MVC grid


I have a Telerik MVC grid that includes a boolean value, CreateIncident. For a new row, I want to set that value to true. For an edit, if the value is already true, I want to disable the checkbox. The Kendo UI apparently added a method to determine if the row is new, but the same call is not accessible in the MVC version. I can intercept the Insert and Update events in C#, but that's after they've clicked on the Save button. I can intercept the edit event in Javascript, which is where the above Kendo answer makes the call.

Alternately, if there is a better way to handle this, I'm open to suggestions.


Solution

  • I found an answer. Inside the javascript, I can do the following check:

    // If this wasn't just created and Create Incident is checked, we already have a value for this, so disable it.
    if (e.dataItem.CreateIncident == true && e.mode == 'edit') {
        $('#CreateIncident').attr("disabled", "disabled");
    }
    

    e.mode is set to 'insert' for new items and edit for older ones. Handy, that.