我有一个剑道网格,在最后一列中有一个复选框,我从服务器端绑定这个网格(填充来自服务器的数据),并且复选框值也来自服务器。我想禁用整个行,其中复选框值为真,即它被选中,并希望允许编辑时,复选框值为假,即它没有被选中。我的代码如下:
@(Html.Kendo().Grid(Model)
.Name("UpdatedHeadGrid")
.Columns(columns =>
{
columns.Bound(p => p.ID).Hidden(true).ClientTemplate("#= ID#" + "<input type='hidden' class='ID' value='#=ID#' />").Width(10);
columns.Bound(p => p.IsAllocated).HeaderHtmlAttributes(new { title = "Allocatable" }).Title("Allocatable").ClientTemplate("<input type='checkbox' ${ IsAllocated == true ? checked='checked' : ''} class='IsAllocated' value='#=data.IsAllocated#' style='width:50px;' />").Width(50).HtmlAttributes(new { style = "text-align: center;vertical-align: middle;"});
columns.Bound(p => p.Total).HeaderHtmlAttributes(new { title = "Total Amount" }).Title("Total").ClientTemplate("<input type='text' disabled='disabled' class='Total' value='#=data.Total#' style='width:65px;' />").Width(60).HtmlAttributes(new { style = "text-align:right", onclick = "DisableEdit(this)" });
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Events(e =>
{
e.DataBound("onRowBound");
e.Edit("onEdit");
})
.PageSize(15)
.Resizable(resize => resize.Columns(true))
)
为此,我编写了编辑函数,即onEdit函数,如下所示:
<script>
function onEdit(e)
{
var fieldName12548 = e.container.find('input[type="checkbox"][name="IsAllocated"]').attr("value");
if (fieldName12548 === "Total") {
this.closeCell();
}
}
</script>
这里,而不是只有列与fieldname="Total"我必须禁用所有的行
为此,您应该使用数据源为::
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.ID);
model.Field(p => p.Total).Editable(false);
})
.PageSize(15)
)
在上面的代码中,我将可编辑模式设置为'false',这将禁用单元格。
我有一个稍微不同的情况:只允许编辑字段d2的值(单元格),当字段d1的值为x或y。
$("#questions-grid").kendoGrid({
...
...
edit: function(e) {
var $row = e.container;
var $input = $row.find("input");
if ($($input).attr("id") === 'field2') {
if (e.model.field1 !== 1) {
$input.remove();
// option b: use this.closeCell(); // if triggering cellClose is ok
}
}
},
cellClose: function(e) {
if (e.model.dirty) {
updateRow(e.model);
}
}
}