When creating grid. How I can make certain columns read only

1 Answer 697 Views
Grid
Salma
Top achievements
Rank 1
Iron
Salma asked on 24 Nov 2021, 06:39 AM
HI Using asp.net mvc .net (not core).  I want to disable columns for edit. Person can read it but cannot overrite it.  How I can do that?

1 Answer, 1 is accepted

Sort by
1
Accepted
Yanislav
Telerik team
answered on 26 Nov 2021, 02:43 PM

Hello Amir,

This is possible when using Inline or InCell editing mode. You can specify a column as a read-only in the Grid DataSource model configuration with the 'Editable(false)' option.

.DataSource(dataSource => dataSource
    .Ajax() // or .Server()
    .Model(model =>
    {
        // Declare a model field and make it readonly
        model.Field(p => p.UnitPrice).Editable(false);
    })
)

 

Regards,
Yanislav
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Salma
Top achievements
Rank 1
Iron
commented on 28 Nov 2021, 12:15 AM

Thanks for the suggestion. but what if I am using the popup.  Can't I hide or disable when using the popup?

I read on other thread and tried to implment the below. 

The recommended resoution is working but it hides the column from the main grid.

        [ScaffoldColumn(false)]
        public int Id { get; set; }

I want to show the column "Date Entetred' on the grid but I want to hide it when user editing the row or when user saving a new data.  

Similarly, I want to make a read only field when user is editing or saving.  For example, I want to show the grid with the UserId,

but i do not want to make it readonly.  I used the below code but it is not working for popup.  

I used to disable the field model.Field(p => p.​ID).Editable(false);

Yanislav
Telerik team
commented on 30 Nov 2021, 08:40 AM

Hi,

By default, the 'PopUp editor' is generating fields for each property of the Model passed to the Grid based on its value. 

If a custom editor is needed, I recommend you to review the following demo:

https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/custom-popup-editor

It demonstrates how to implement a custom editor and how to configure the Grid to use it.

This way, you'll have full control over which fields to be shown and how to be shown.

Regards,
Yanislav
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
Salma
Top achievements
Rank 1
Iron
Answers by
Yanislav
Telerik team
Share this question
or