Kendo UI Grid .Net MVC - Column editable in Creation only

a 夏天 提交于 2019-12-13 07:26:18

问题


I've been searching how to make a column in a Kendo Grid ASP.Net MVC (Razor) Editable only while we are in creation and not editable while in update.

Is there something special that will help me accomplish this task?


回答1:


You can bind a custom function to the onEdit event and make that column readonly:

@(Html.Kendo().Grid<DemoType>()
      .Name("grid")
      .Columns(columns =>
      {
         /*...*/
      })
      .Events(events => events
          .Edit("onEdit")
      )
  )

Javascript:

function onEdit(e) {
    if (e.model.isNew() == false) {
        //$('[name="YourcolumnName"]').attr("readonly", true);
        //replace input with span
        //taken from https://stackoverflow.com/questions/3142990/jquery-replace-inputs-with-spans
        $('[name="YourcolumnName"]').each(function() {
          $("<span />", { text: this.value}).insertAfter(this);
          $(this).hide();
       });
    }
}


来源:https://stackoverflow.com/questions/45166226/kendo-ui-grid-net-mvc-column-editable-in-creation-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!