我在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%" }
]
});
注意这是剃刀语法。
@(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);
}