[英]Disable the row in the kendo grid based on condition
我有一個Kendo網格,其中的最后一列有一個復選框,我從服務器端綁定此網格(填充服務器中的數據),並且該復選框的值也來自服務器。我想禁用復選框值為true的整個行(即選中該行),並希望在復選框值為false(即未選中)時允許進行編輯。 我的代碼如下:
@(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>
在這里,我必須禁用所有行,而不僅僅是字段名稱為“ Total”的列。
用於編輯多個列
var fieldName = e.container.find("input").attr("name");
if (fieldName === "AccountTransactionItemDescription" && fieldName === "Identifier" && fieldName === "TradeOrNonTrade" && fieldName === "EntityName")
{
this.closeCell();
}
但是在這里可能行不通,這可能只能引用一個。那么對此有什么解決方案?
建議您不要在事件處理程序參數e
的字段中使用model
,而不要使用jQuery來查找輸入的值。
因此,您應該執行以下操作:
<script>
function onEdit(e) {
if (e.model.IsAllocated) {
this.closeCell();
}
}
</script>
在此處查看其運行情況: http : //jsfiddle.net/OnaBai/ry82wcvc/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.