9

I have a question on how to implement the readonly on edit in kendo UI. see below for detailed explanation

I have the following Fields:

FirstName (editable on create) (editable on edit)
LastName (editable on create) (editable on edit)
UserName (editable on create) (readonly on edit)
Email (editable on create) (editable on edit)
TelephoneNumber (editable on create) (editable on edit)
PreWin2KUserName (not editable on create)(readonly on edit)

Using the Kendo UI Grid Reference Link http://demos.kendoui.com/web/grid/editing-inline.html

plus this to implement http://www.kendoui.com/forums/ui/grid/making-column-as-readonly-on-update-and-editable-on-insert-in-grid.aspx

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1825918
  • 121
  • 1
  • 1
  • 3

1 Answers1

10

You could use the edit event of the Grid. If the model is not new i.e. the user is editing (not creating) the record you attach the readonly attribute to the desired input element.

$('#yourGrid').kendoGrid({
     // ...
     edit: function(e) {
         if (!e.model.isNew()){
             // make sure the UserName id selector is correct in your code
             // (it should be, for a regular text input)
             $('#UserName').attr('readonly', 'readonly');
         }
     }
})
Alex Gyoshev
  • 11,929
  • 4
  • 44
  • 74
Petur Subev
  • 19,983
  • 3
  • 52
  • 68