This is a migrated thread and some comments may be shown as answers.

How to specify only some Fields as Editable in Grid Edit PopUp.

10 Answers 793 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg Gum
Top achievements
Rank 1
Greg Gum asked on 17 Dec 2013, 07:12 PM
I have a Kendo Grid with pop-up editing. 

How do I specify that only some of the columns are editable?  Or that some are read-only?

I have tried this in the viewmodel, but it doesn't seem to affect the Edit Popup:

The Display annotation does work however.
          [Display(Name = "Type Id")]
       [Editable(false)]
       public int ReportTypeId { get; set; }

10 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 19 Dec 2013, 09:01 AM
Hi Greg,

Which columns are editable can be specified in the Grid's DataSource configuration using the editable option in the schema model. For example:  
.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .Model(model => {
        model.Id(p => p.ProductID);
        model.Field(p => p.ProductName).Editable(false);
    })


Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
John
Top achievements
Rank 1
answered on 24 Mar 2017, 11:03 AM

Hi Alexander

i am trying to do the same thing with .net core version and is not working....

Do i have to use template?

 

this is my Index.cshtml

@(Html.Kendo().Grid<PriceProject.Models.PricesModels.Category>()
        .Name("Categories")
        .Columns(columns =>
        {
            columns.Bound(c => c.ID);
            columns.Bound(c => c.CategoryName);
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
        })
        .ToolBar(toolbar =>
        {
            toolbar.Create().Text("New Category");
            toolbar.Save();
        })
        .Editable(editable => editable.Mode(GridEditMode.PopUp))
        .Pageable()
        .Navigatable()
        .Sortable()
        //.Scrollable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .ServerOperation(true)
            .Model(model =>
            {
                model.Id(p => p.ID);
                model.Field(p => p.ID).Editable(false);
                model.Field(p => p.CategoryName).Editable(true);
                model.Field(p => p.UserID).DefaultValue(1).Editable(false);

            })
            .Read(read => read.Action("GetCategories", "Categories"))
            .Create(create => create.Action("Create", "Categories"))
            .Update(update => update.Action("Edit", "Categories"))
            .Destroy(update => update.Action("Delete", "Categories"))
            .PageSize(10)
        ).Deferred()
)

0
Stefan
Telerik team
answered on 28 Mar 2017, 08:04 AM
Hello John,

I was not able to reproduce the same issue on my end. Still, I will make an additional investigation to ensure that the Core version is not causing unexpected issues.

I can suggest checking the following example how to make a column editable based on a condition. If the column has to be non-editable all of the time, the function can return false in all scenarios:

http://docs.telerik.com/aspnet-mvc/helpers/grid/how-to/editing/conditionally-editable-columns

I hope this will help to achieve the desired result.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Dome
Top achievements
Rank 1
answered on 28 Jan 2021, 04:29 PM

Hi I renew this post with same issue in ASP.NET Core 5. Editable("<js func>") doesn't work. Returning false from function still let edit the fields (columns). Also using [Editable()] decoration and Model field Editable are ignored. 

The only way seems [ScaffoldColumn()] decoration but this doesn't display the columns at all in the grid. 

0
Tsvetomir
Telerik team
answered on 01 Feb 2021, 12:40 PM

Hi Dome,

When the Telerik UI Grid utilizes the PopUp editor, the Editable option would not hide the editor. This is due to the fact that the server-side uses the "EditorForModel" helper that creates the whole editor base on the data types of the field and return it as-is. Since this is on the server-side, at the time it is sent to the client, it is too late to hide the columns. 

What I can recommend is that you subscribe to the Edit event and hide the respective editor manually. It should have the ID attribute set to the name of the field.

Alternatively, you can create and return a custom editor that will feature only the needed editors. 

 

Kind regards,
Tsvetomir
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/.

0
Dome
Top achievements
Rank 1
answered on 01 Feb 2021, 01:58 PM
Thank you, I solved with custom editor feature and it works fine.
0
Jack
Top achievements
Rank 1
answered on 18 Feb 2021, 09:05 AM
If you explicitly set .Visible(true) on the column you still want to show they will appear in the grid but not the popup editor.
0
Tsvetomir
Telerik team
answered on 18 Feb 2021, 07:44 PM

Hi Jack,

Thank you for sharing your suggestion on how to handle the case. However, I am not completely sure what exacty the scenario you are working is. 

By design, the columns have the Visible option set to true, therefore, you might have additional code that is disabling the editing of certain fields. Could you share them so that we make it clear for other members of the community that might come across this thread?

 

Best regards,
Tsvetomir
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/.

0
Jack
Top achievements
Rank 1
answered on 19 Feb 2021, 08:50 AM

Hi,

Yeah sorry i wasn't very clear - I was replying to Dome's response about the [ScaffoldColum(false)] attribute usage to remove the item for edit in the popup window but it in turn hiding the columns in the Grid as well. When i have then explicitly set Visible(true) on the attributed column in the View it has then appeared in the Grid but remains disabled in the editor.

I'm not sure if this is the intended behaviour of the controls but it solved this exact issue for me.

 

Jack

0
Tsvetomir
Telerik team
answered on 22 Feb 2021, 04:18 PM

Hi Jack,

Thank you for taking the time to go into the detail on what has worked on your side! 

Indeed, the ScaffoldColumn does play a role in the appearance of the grid. This is due to the fact that it default the Visible option to false so that the column should not be rendered at all. However, it is overridden by the .Value() option of the column. Hence, the column is not used for editing but it is being shown.

 

Kind regards,
Tsvetomir
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
Greg Gum
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
John
Top achievements
Rank 1
Stefan
Telerik team
Dome
Top achievements
Rank 1
Tsvetomir
Telerik team
Jack
Top achievements
Rank 1
Share this question
or