【问题标题】:Disable/Enable the checkbox in kendo grid based on column Value根据列值禁用/启用剑道网格中的复选框
【发布时间】:2014-05-23 04:11:14
【问题描述】:

我有一个 kendogrid 一切正常,现在我有了新的要求,即我有复选框的最后一列,就在前一列我有一个状态列,

如果该文本值为“CERTIFIED”,则应启用该特定行复选框,如果文本不是“CERTIFIED”,则应禁用该行的复选框,并且不应允许使用 jquery 检查该复选框,我附上了我的 kendogrid 的图片,这可能有助于提供任何建议

代码

这些是我的剑道网格中的列

, 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,
           }
         ]

这是我的个人行复选框

<script id="template" type="text/kendo-template">
   #if(ResultFormatID != 3) { #   
   <input type="checkbox" #= data.Action ? checked="checked" : "" #  class=\"check_row\"/>
   # } else { #
<input type="button" class="k-button info" name="info" value="Preview" />
   # } #

更新

这是我的检查功能(以及我取消选中的操作)

 $("#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();
        }

    });

});

更新 2

现在根据您的代码,一切正常,我可以取消选中未认证的行,我面临以下代码的问题,如果未选中至少一个复选框,它禁用了用于下载 PDF 的按钮文件,现在如果我选择所有复选框并单击该按钮下载,它现在被禁用!但如果我取消选中 10 行中的任何一行,则下载启用并用于下载文件。

如果我禁用下面代码的最后 3 行,它有助于使按钮能够单击,但我需要取消选择至少一个复选框才能工作,如果不是它将被禁用,我做错了什么??

 $(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)
        });
    });

如果

【问题讨论】:

    标签: jquery asp.net-mvc-4 checkbox kendo-grid


    【解决方案1】:

    似乎您需要控制type="checkbox"input 字段是否为disabled。所以你应该将模板定义如下:

    <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>
    

    即:添加data.Status == 'Certified' ? disabled='disabled' : ""的条件

    在此处查看实际操作:http://jsfiddle.net/Hfk3Q/

    编辑:单击标题复选框时所需的更改将更改其实现以仅检查未禁用的单元格。比如:

    $('.check_row:not(:disabled)', grid.tbody).prop('checked', true);
    

    在此处查看实际操作:http://jsfiddle.net/Hfk3Q/3/

    【讨论】:

    • 感谢@OnaBai 的回复,这件事我已经在条件方面进行了修复,有一个小问题,我需要禁用该复选框的原因是因为不应该检查该行用户,但如果我选择标题模板“全选”,它会选择所有内容,包括禁用的一个,我不需要,我只需要那些启用状态的行,我附上了上面的图片,如果可能请验证它
    • 我建议您更改selectAll 代码以不选择禁用的代码,这在 jQuery 中很容易控制。
    • 检查我的 EDIT 建议实现检查所有未禁用的功能。
    • 是的,看起来很简单,我搜索的时候甚至代码都很简单,但是实现后它并没有改变它的状态,上面我分享了我的“checkAll”代码,有条件,状态值显示正确,但是当它去循环取消选中它没有检查时,你能找到我有什么问题吗
    • 感谢您的代码,我需要认证为“启用”而不是认证为“禁用”我如何才能否定模板中的条件?连同我已经实现了你的代码,但全选仍然检查禁用的行!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 2013-04-17
    • 2013-11-24
    • 1970-01-01
    相关资源
    最近更新 更多