【问题标题】:How to disable checkbox of a row in kendo grid using javascript function如何使用javascript函数禁用剑道网格中一行的复选框
【发布时间】:2019-08-30 06:28:00
【问题描述】:

我有一个剑道网格,其中定义了列,2 列是复选框类型。基于 cmets 行数据中的一些验证,我想禁用网格中该特定行的复选框。
我有一个单独的 javascript 函数用于验证,但我无法禁用该行的复选框。我正在添加剑道网格代码和 javascript 函数。

剑道网格:

createGrid: function (data) {
    $("#ProductGrid").kendoGrid({
        dataSource: {
            data: tableData
        },
        columns: [        
            { field: "Accept", tilte: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Accept), "template": "<input type=\"checkbox\" />" },
            { field: "Decline", tilte: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Decline), "template": "<input type=\"checkbox\" />" },
            { field: "Item", tilte: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Item) },
            { field: "PartID", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.PartID) },
            { field: "Description", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Description), width:'300px' },
            { field: "SubPart", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPart) },
            { field: "SubPartDescription", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPartDescription) },
            { field: "BusinessPartner", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.BusinessPartner) },
            { field: "ReqDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.ReqDelTM) },
            { field: "EarDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.EarDelTM) },
            { field: "EarDelDate", title: "Ear Del Date", hidden: true },
            { field: "Comments", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Comments) },        
        ]
    });
},

JS函数:

checkComments: function () {
    var productGrid = $("#ProductGrid").data("kendoGrid");
    var productGridData = productGrid.dataSource;
    var noofproduct = productGridData.data().length;
    var dataList = productGridData.data();  

    for (var i = 0; i < noofproduct; i++)
    {
        if (dataList[i].Comments == "Date not met")
        {
            (dataList[i].Accept.enable(false));      
        }
    }
}

【问题讨论】:

    标签: checkbox kendo-ui kendo-grid


    【解决方案1】:

    您可以使用剑道模板按条件禁用复选框。

      var data = [
        {disabled: false}, 
        {disabled: true}, 
        {disabled: false}
      ];
    
      $('#grid').kendoGrid({
        dataSource: data,
        columns: [{
          title: "checkbox",
          template: function (item){
            return "<input type='checkbox' " + (item.disabled ? 'disabled': '') + ">"}
        }]
      });
    

    你可以试试这个解决方案here

    【讨论】:

    • @Maximilain 。当我添加这个函数时,整行都被禁用了。你能帮帮我吗?
    • @Zabi 提供代码示例来重现您的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多