Jquery 基于列值禁用/启用剑道网格中的复选框
我有一个kendogrid所有工作正常,现在我有了新的要求,即最后一列我有复选框,就在前一列我有一个状态列 如果该文本值仅为“认证”,则应启用特定行复选框,如果该文本未“认证”,则应禁用该行的复选框,并且不允许使用jquery检查该复选框,我已附上kendogrid的图片,这可能有助于任何建议 代码 这些是我剑道格网中的栏Jquery 基于列值禁用/启用剑道网格中的复选框,jquery,asp.net-mvc-4,checkbox,kendo-grid,Jquery,Asp.net Mvc 4,Checkbox,Kendo Grid,我有一个kendogrid所有工作正常,现在我有了新的要求,即最后一列我有复选框,就在前一列我有一个状态列 如果该文本值仅为“认证”,则应启用特定行复选框,如果该文本未“认证”,则应禁用该行的复选框,并且不允许使用jquery检查该复选框,我已附上kendogrid的图片,这可能有助于任何建议 代码 这些是我剑道格网中的栏 , columns: [ { field: "ResultFormatID", Title: "ResultFormatID", filterable
, columns: [
{ field: "ResultFormatID", Title: "ResultFormatID", filterable: false, sortable: false, hidden: true },
{ field: "ID", Title: "ID", filterable: false, sortable: false, hidden: true },
{ field: "RowID", Title: "RowID", filterable: false, sortable: false, hidden: true },
{ field: "BillNumber", Title: "Bill Number", filterable: false, sortable: false, hidden: true },
{ field: "ServiceName", Title: "Service Name", width: 600 },
{ field: "Status", Title: "Service Status", width: 150 }
, {
template: $("#template").html(),
headerTemplate: '<label> <input type="checkbox" id="checkAll"/>Download</label>', filterable: false, sortable: false, width: 100,
}
]
如果
似乎您需要的是控制
type=“checkbox”
的输入字段是否被禁用。因此,您应该按照以下方式定义模板:
<script id="template" type="text/kendo-template">
#if(ResultFormatID != 3) { #
<input type="checkbox" #= data.Action ? checked="checked" : "" # class=\"check_row\" #= data.Status == 'Certified' ? disabled='disabled' : "" #/>
# } else { #
<input type="button" class="k-button info" name="info" value="Preview" />
# } #
</script>
在这里查看操作:感谢回复@OnaBai,我已经修复了关于条件的问题,有一个小问题,我需要禁用该复选框的原因,因为用户不应该选中该行,但如果我选择标题模板“全选”,它会选择包括禁用一行在内的所有内容,我不需要,我只需要那些状态为已启用的行,我已附上上面的图片,如果可能,请验证我建议您更改selectAll
code以不选择已禁用的行,这在jQuery中很容易控制。请使用建议的函数实现检查我的编辑,以检查所有未禁用的功能。是的,这看起来很容易,即使代码在我搜索时非常简单,但在实现后它并没有改变其状态,上面我共享了我的“checkAll”代码,带有条件,状态值显示正确,但是当它进入循环取消选中时,它不是在检查,你能找到我哪里出了问题吗谢谢你的代码,我需要认证为“启用”而不是“禁用”我怎么能在模板中否定条件??除此之外,我还实现了您的代码,但是selectall仍然会检查禁用的行!!!
$("#checkAll").on('click', function (e) {
debugger;
var $cb = $(this);
var checked = $cb.is(':checked');
var grid = $('.Grid_table').data('kendoGrid');
grid.table.find("tr").find("td:last input").attr("checked", checked);
var items = $(".Grid_table").data("kendoGrid").dataSource.data();
for (i = 0; i < items.length; i++) {
var item = items[i];
var status = item.ServiceStatus;
if (status == "Result Certified ") {
grid.table.find("tr").find("td:last input").attr("checked", checked);
}
else {
grid.table.find("tr").find("td:last input").prop("checked",false);
}
if (!checked) {
// debugger;
$(".Grid_table").data("kendoGrid").clearSelection();
}
});
});
$(function () {
//debugger;
var checkboxes = $(':checkbox:not(#checkAll)').click(function (event) {
$('#btn_Print').prop("disabled", checkboxes.filter(':checked').length == 0);
});
$('#checkAll').click(function (event) {
checkboxes.prop('checked', this.checked);
$('#btn_Print').prop("disabled", !this.checked)
});
});
<script id="template" type="text/kendo-template">
#if(ResultFormatID != 3) { #
<input type="checkbox" #= data.Action ? checked="checked" : "" # class=\"check_row\" #= data.Status == 'Certified' ? disabled='disabled' : "" #/>
# } else { #
<input type="button" class="k-button info" name="info" value="Preview" />
# } #
</script>
$('.check_row:not(:disabled)', grid.tbody).prop('checked', true);