MVC Grid columns locked for edit but not for create?

1 Answer 36 Views
Grid
Jonathan
Top achievements
Rank 1
Jonathan asked on 14 Sep 2021, 04:59 PM

Hello

I have a situation where I have a number of columns that are supposed to be read only for editing.  However, I would like for the user to be able to enter in values for those columns when creating a new record.

Is this possible with Grid?

I have something like


@(Html.Kendo().Grid<View_Model>()
    .Name("RecordGrid")
    .Columns(column =>
    {
         columns.Bound(o => o.model_id).Hidden();
         columns.Bound(o => o.supplier_id).Title("Supplier ID").Width(150)
         //...about 20 more columns
         columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200).Locked();
   }
   .ToolBar(toolbar => toolbar.create())
   .Editable(editable =>
   {
         editable.Mode(GridEditMode.Inline)
         .ConfirmDelete(Constants.CONFIRM_REC_DELETE);
    })
    //... etc
    .DataSouce(dataSource => dataSource
          .Ajax()
          .Model(model =>
          {
               model.Id(o => o.model_id);
               model.Field(o => o.supplier_id); //.Editable(false);
//and then just the remaining model fields and the create/read/etc functions

supplier_id (and a few others) I'd prefer to have as read_only (especially being a foreign key) but I need it available for create as ideally I'd have the user pick a supplier and under the hood it gives me the supplier_id foreign key.

I'd like to know if this is possible, because I have about 4-5 fields (and supplier_id is the only FK among them) that should be readonly for edit, but not for create.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 Sep 2021, 12:08 PM

Hello Jonathan,

 

Thank you for writing to us.

You can achieve this requirement using the .Events(e=>e.Edit("myFunction")) approach.

And once you are inside the edit handler function, you can use the e.model.isNew() to determine when to hide the field editors, as demonstrated here:
https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/edit

Feel free to give it a try and let me know if this helps you.

How can I assist you further to achieve what you are looking for?

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or