【问题标题】:Kendo Grid jQuery - Editable CellKendo Grid jQuery - 可编辑单元格
【发布时间】:2014-09-30 18:51:13
【问题描述】:

我在 jquery 中构建了一个剑道网格,我希望允许用户编辑它的特定单元格。问题是我知道有一种方法可以编辑整行,像这样:

$("#gridItens").kendoGrid({
      editable: true,
      columns: [
         ...
      ]
 });

它工作正常,但正如我之前所说,它允许用户编辑整行,而不是特定的单元格。我尝试了类似上面的代码,但它不起作用。

$("#gridItens").kendoGrid({
      columns: [
         { field: "Number", title: "Number", width: "10%", editable: true }
      ]
 });

有没有办法让单元格可编辑?

谢谢 ;)

更新

我找到了解决方案。该解决方案与我所做的不同之处在于,每列的配置必须在架构部分中,而不是在列部分中。

$("#gridItens").kendoGrid({
       dataSource: {
            type: "json",
            transport: {
                read:
                    {
                        url: "/RC/BuscarItensContrato",
                        data: { contratoId: 0 },
                        contentType: "application/json; charset=utf-8",
                        dataType: "json"
                    }
            },
            schema: {
                model: {
                    fields: {
                        Id: { type: "number" },
                        Descricao: { type: "string", editable: false },
                        Numero: { type: "number", editable: true }
                    }
                }
            }
        },
        columns: [
            {
                field: "Selecionado",
                title: "",
                sortable: false,
                width: 30,
                headerTemplate: "<input type='checkbox' id='chkSelectAll' />",
                template: "<input type='checkbox' name='gridcheckbox' id='#=Id#' />"
            },
            { field: "Descricao", title: "Descrição", width: "30%" },
            { field: "Numero", title: "Número", width: "10%" }
        ]
 });

【问题讨论】:

  • 要编辑单元格,试试这个函数:console.log(cell.find("input"));
  • 效果很好,谢谢!我必须在 kendoGrid 配置中添加 editable: true 才能使其工作

标签: jquery kendo-grid


【解决方案1】:

注意这是剃刀语法。

@(Html.Kendo().Grid<ViewModel>()
    .Name("grid")
    .Editable(editable => editable.Mode(GridEditMode.InCell))  
    .Columns(columns =>
    {....
}

不允许编辑字段

 .DataSource(dataSource => dataSource
        .Ajax()
        .Read(etc....) 
        .Model(model => 
           {

               model.Field(x => x.Property).Editable(false);
           }

【讨论】:

  • 问题是我不能使用 razor 语法,只能使用 jQuery
  • 好吧,如果我配置可编辑:“incell”,然后为每一列设置可编辑:假或真,它允许编辑所有单元格,如果可编辑被定义为假也没关系跨度>
  • 你的语法一定有问题,这是复制粘贴的代码。
猜你喜欢
  • 2019-08-09
  • 2015-09-21
  • 1970-01-01
  • 1970-01-01
  • 2020-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-14
相关资源
最近更新 更多