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

Make some Grid Columns ReadOnly

1 Answer 854 Views
Grid
This is a migrated thread and some comments may be shown as answers.
adamhughes
Top achievements
Rank 1
Iron
Veteran
adamhughes asked on 16 Apr 2021, 02:35 AM
How do I make some Core Grid columns editable and some readonly?

1 Answer, 1 is accepted

Sort by
1
Mihaela
Telerik team
answered on 20 Apr 2021, 01:22 PM

Hi,

Any column can be enabled/disabled for editing within the edit event handler of the Kendo UI Grid (when the inline "Edit" button is clicked on a specific row). Once the event is fired, you could set the attribute "disabled" with the jQuery method attr() to specified columns.

For example, the code snippet below demonstrates how to disable the column "Ship Name" in edit mode:

@(Html.Kendo().Grid<Model>()
  .Name("grid")
  .Columns(columns =>
  {
     columns.Bound(p => p.ShipName);
     columns.Command(command => { command.Edit(); command.Destroy(); })
   })
   .Events(ev => ev.Edit("onEdit"))
   .Editable(editable => editable.Mode(GridEditMode.InLine))
   ...
)

<script>
      function onEdit(e) {
          var shipNameOption = e.sender.editable.options.model.ShipName;
          var shipNameInput = $('[data-role="editable"] input#ShipName');
          if (shipNameOption) {
              shipNameInput.attr('disabled', 'disabled');
          } else {
              shipNameInput.removeAttr('disabled');
          }
      }
</script>

Would you please give a try of this example and let me know if it applies to your case?

 

Regards, Mihaela Lukanova Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
Grid
Asked by
adamhughes
Top achievements
Rank 1
Iron
Veteran
Answers by
Mihaela
Telerik team
Share this question
or