【发布时间】:2014-10-06 09:40:35
【问题描述】:
我有一个剑道网格,其中最后一列有一个复选框,我从服务器端绑定这个网格(从服务器填充数据)并且复选框值也来自服务器。我想要禁用复选框值为真的整行,即它被选中,并希望在复选框值为假时允许编辑,即它未被选中。 我的代码如下:
@(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" 的列。
【问题讨论】:
标签: javascript jquery asp.net-mvc checkbox kendo-grid