Kendo UI Grid .Net MVC-列只能在创建中编辑 [英] Kendo UI Grid .Net MVC - Column editable in Creation only

查看:125
本文介绍了Kendo UI Grid .Net MVC-列只能在创建中编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索如何在Kendo Grid ASP.Net MVC(剃刀)中创建一列,仅在创建时可编辑,而在更新时不可编辑.

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?

推荐答案

您可以将自定义函数绑定到onEdit事件,并将该列设置为只读:

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:

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();
       });
    }
}

这篇关于Kendo UI Grid .Net MVC-列只能在创建中编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆