How to make a grid column with checkbox read-only when adding a new record

1 Answer 111 Views
Grid
PaulH
Top achievements
Rank 1
PaulH asked on 06 Apr 2022, 03:59 PM

I have a maintenance grid for data where one of the columns is an "Archived?" column which should be read-only when adding a new record or editable otherwise - database/data layer will default the value to false in any case. How can I achieve that? The relevant column in my grid is defined as follows:


            columns.Bound(t => t.IsArchived).ClientTemplate("<input type='checkbox' onclick='return false;' #= IsArchived ? checked='checked' : '' # />").HtmlAttributes(new { style = "text-align: center;" }).HeaderHtmlAttributes(new { style = "text-align: center;" }).Width(140);

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 11 Apr 2022, 08:57 AM

Hi, Paul,

If you would like to disable the editor only when a new record is added, I could recommend using the Edit event of the widget. Namely:

.Events(ev=>ev.Edit("onEdit"))
// .   .    .
function onEdit(e) {
    if (e.model.isNew()) {
      // Disable the editor
    }
  }

I hope you find this helpful.

 

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
PaulH
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or