Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI - How to make specific fields readonly on edit while on create its editable in kendo grid?

Tags:

kendo-ui

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

like image 902
user1825918 Avatar asked Nov 15 '12 07:11

user1825918


People also ask

How do I make my Kendo grid readonly?

k-button and/or . k-button-icontext) to set readonly or disabled. The toolbutton works, but the in-row Edit and Delete buttons may not be changed (always clickable). Do you have any trick to achieve it?

How do I turn off edit in kendo grid?

data("kendoGrid"); $grid.dataSource.at(0). fields["cell"]. editable = false; Save this answer.


1 Answers

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');
         }
     }
})
like image 79
Petur Subev Avatar answered Sep 28 '22 23:09

Petur Subev