我有一个应用程序,我有一个KendoGrid,其中有2列。在第一列我附加一个标签基于条件现在我想为每一行禁用此列。我正在使用Incell编辑为编辑列的数据所以当我通过InCell编辑KendoGrid进行编辑时单击第一列时必须禁用它,不能编辑。 这里我的代码如下:
@(Html.Kendo().Grid(Model)
.Name("Remark")
.TableHtmlAttributes(new { style = "height:20px; " })
.Columns(columns =>
{
columns.Bound(p => p.RemarkID).Hidden(true).ClientTemplate("#= RemarkID#" + "<input type='hidden' class='RemarkID' value='#=RemarkID#' />");
//columns.Bound(p => p.RemarkCode).Title("Remark Code").Width(3).ClientTemplate("#= RemarkCode#" + "<input type='hidden' class='RemarkCode' value='#=RemarkCode#' />");
columns.Bound(p => p.RemarkDescription).Title("Type").Width(10).ClientTemplate("#= RemarkDescription#" + "<input type='hidden' class='RemarkDescription' value='#=RemarkDescription#' />");
columns.Bound(p => p.Remark).Title("Remark").Width(50).ClientTemplate("#= Remark#" + "<input type='hidden' class='Remark' value='#=Remark#' />");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Navigatable()
.Sortable()
.Scrollable(scr => scr.Height(200))
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
model.Id(p => p.RemarkID)
)
.Create("Editing_Create", "Grid")
.Read("Remark_Read", "Document")
.Update("Editing_Update", "Grid")
.Destroy("Editing_Destroy", "Grid")
)
)
$(".AddNewRemark").click(function () {
//grid.addRow();
var dataSource = grid.dataSource;
var total = dataSource.data().length;
dataSource.insert(total, {});
dataSource.page(dataSource.totalPages());
grid.editRow(grid.tbody.children().last());
var it = $(this).text().trim();
$("#RemarkDescription").val(it);
$("#RemarkDescription").attr('readonly', 'readonly');
grid.dataSource._data[total].RemarkDescription = it;
for(var i=0;i<=total;i++){
grid.dataSource.at(i).fields["RemarkDescription"].editable=false;
}
});
答案 0 :(得分:3)
试试这个, 这只是一个例子,
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true },editable: false, },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 430,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 110 },
{ field: "UnitsInStock", title: "Units In Stock", width: 110 },
{ field: "Discontinued", width: 110 },
{ command: "destroy", title: " ", width: 90 }],
editable: true
});
});
</script>
</div>
如果您想在Incell Editing Grid中Disable
一列,请使用editable: false
作为该列。
如果您对网格列使用editable: false
属性,并且想要在该网格中添加新项目,则第一列应始终为Disabled
。我不知道用于Razor语法的ans。
答案 1 :(得分:0)
在要禁用的特定列的架构声明中将editable设为false。