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
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
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()
)
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
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.
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/.
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/.
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
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/.