Javascript 启用单元格编辑剑道网格

Javascript 启用单元格编辑剑道网格,javascript,asp.net-mvc,kendo-grid,Javascript,Asp.net Mvc,Kendo Grid,我很不好意思提出这样的问题,但我绝望了。我是剑道新手,我很容易使我的网格可编辑。 这是我的密码 @(Html.Kendo().Grid<Server.Models.MasterFoo>() .Name("gridRules") .HtmlAttributes(new { style = "height:300px; margin: 0px" }) .Columns(columns => {

我很不好意思提出这样的问题,但我绝望了。我是剑道新手,我很容易使我的网格可编辑。 这是我的密码

 @(Html.Kendo().Grid<Server.Models.MasterFoo>()
        .Name("gridRules")
        .HtmlAttributes(new { style = "height:300px; margin: 0px" })
        .Columns(columns =>
        {
            columns.Bound(c => c)
                .ClientTemplate("<input type='checkbox' class='checkbox' />")
                .Width(24);
            columns.Bound(c => c.ID)
                .Hidden(true);
            columns.Bound(c => c.Name);
            columns.Bound(c => c.Description)
                .EditorTemplateName("Descriptions")
                .Title("SpecialDescription");
        })
        .DataSource(ds => ds
            .Ajax()
            .Model(m =>
            {
                m.Id(f => f.ID);
                m.Field(f => f.Name).Editable(true);
                m.Field(f => f.Description).Editable(true);
            })
            .Read(read => read.Action("GetFooBar", "MyController", new { area = "Administration" })
                .Data("foo.param"))
            .Update(update => update.Action("UpdateFoo", "MyController", new { area = "Administration" })
                .Data("foo.param"))
            .Batch(true)
        )
        .Events(events => events
            .SaveChanges("foo.gridChanged")
            //.Edit("foo.gridChanges")
            //.Change("foo.gridSelection")
            .DataBound("foo.gridDataBound")
        )
        .Resizable(r => r.Columns(true))
        .Scrollable()
        .Navigatable()
        //.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
        .AutoBind(false)
        .Sortable(sortable => sortable.AllowUnsort(false))
        //.Editable(editable => editable.Mode(GridEditMode.InCell))     
    )
@(Html.Kendo().Grid())
.名称(“网格规则”)
.HtmlAttributes(新的{style=“高度:300px;边距:0px”})
.列(列=>
{
columns.Bound(c=>c)
.ClientTemplate(“”)
.宽度(24);
columns.Bound(c=>c.ID)
.隐藏(真实);
columns.Bound(c=>c.Name);
columns.Bound(c=>c.Description)
.EditorTemplateName(“说明”)
.标题(“特殊说明”);
})
.DataSource(ds=>ds
.Ajax()
.Model(m=>
{
m、 Id(f=>f.Id);
m、 字段(f=>f.Name)。可编辑(true);
m、 字段(f=>f.Description)。可编辑(true);
})
.Read(Read=>Read.Action(“GetFooBar”、“MyController”、new{area=“Administration”})
.Data(“foo.param”))
.Update(Update=>Update.Action(“UpdateFoo”,“MyController”,new{area=“Administration”})
.Data(“foo.param”))
.Batch(真)
)
.Events(Events=>Events
.SaveChanges(“foo.gridChanged”)
//.Edit(“foo.gridChanges”)
//.Change(“foo.gridSelection”)
.DataBound(“foo.gridDataBound”)
)
.可调整大小(r=>r.Columns(true))
.Scrollable()
.Navigatable()
//.Selectable(可选=>Selectable.Mode(GridSelectionMode.Single))
.AutoBind(假)
.Sortable(Sortable=>Sortable.alloworst(false))
//.Editable(Editable=>Editable.Mode(GridEditMode.InCell))
)
现在我遇到了一个问题:我无法编辑我的网格。 如果我添加//.Editable(Editable=>Editable.Mode(GridEditMode.InCell)),它根本不起作用。我在使用剑道2013年第2季度,我错过了什么? 提前谢谢

更新以下是每当我启用
Editable(Editable=>Editable.Mode(GridEditMode.InCell))
此代码很好:

.Editable(editable => editable.Mode(GridEditMode.InCell))
但您还需要工具栏中的“保存”按钮:

.ToolBar(toolbar =>
            {
                toolbar.Save();
            })
剑道文档摘录:

  • 通过设置启用内联单元格编辑:.Editable(Editable=>Editable.Mode(GridEditMode.InCell))启用添加新记录,保存 通过设置工具栏上的“更改”和“放弃更改”按钮: .ToolBar(ToolBar=>{ToolBar.Create();ToolBar.Save();}
  • 在数据源声明中设置.Batch(true)和.ServerOperation(false)属性,以启用批更新并执行分页, 客户端上的排序、筛选和分组操作
  • 在数据源中调用CRUD操作方法

发现我只需要在模型中添加无参数构造函数

public class MasterFoo {
     public MasterFoo() {}
}
以下是我学到的教训:

  • 剑道UI网格绑定到模型,并在添加一些属性/属性(如可编辑和可过滤)后实例化它的一个实例
  • 永远不要忽略错误消息
  • 最重要的是,如果无法解决你的bug,不要自杀。试着问问社区,如果仍然没有,回家睡一觉

  • 您只需将以下内容添加到columns集合中:
    columns.Command(c=>c.Edit());
    这将为您启用编辑按钮。我要做的是直接在单元格上编辑它,我有一个工具栏按钮,其中包括“保存”按钮,并将在每次添加时验证更改并保存所有有效更改。可编辑(editable=>editable.Mode(GridEditMode.InCell))我的单元格变了。我的程序坏了。我的文本变为绿色