Kendo ui添加新记录时禁用列

时间:2019-01-02 01:56:28

标签: javascript kendo-ui radio-button kendo-grid

该如何实现,我只想在添加新记录并选中时禁用状态列上的单选按钮。

enter image description here

我不知道应该给脚本的哪一部分。但是我在这里提供了一些。

我的KendoGrid脚本

        $("#grid").kendoGrid({
        dataSource: dataSource,
        dataBound: setColor,
        height:400,
        sortable: true,

        columns: [ 
            { field: "segmentActive", title:"STATUS", width: "120px", editor: RadioSegmentActive, 
              template: data => data.segmentActive == "y" ? "Yes" : "No" }, // <-- displaying Yes/No insted of y/n

            { field: "marketSegmentName", title:"SEGMENT NAME", width: "120px" },

            { field: "publicPrice", title:"PUBLIC PRICE", width: "120px", editor: RadioPublicPrice,
              template: data => data.publicPrice == "y" ? "Yes" : "No"},

            { field: "isHouseUse", title:"HOUSE USE", width: "120px", editor: RadioHouseUse,
              template: data => data.isHouseUse == "y" ? "Yes" : "No"},

            { command: ["edit",{ name: "destroy", text: "De-active" }], title: "&nbsp;", width: "120px" },
        ],
        editable: "inline",
        ...........

我的RadioSegmentActive函数

function RadioSegmentActive(container, options) {
var guid = kendo.guid();

    $('<input class="k-radio" id="radio3" name="segmentActive" type="radio" value="y" >').appendTo(container);
    $('<label class="k-radio-label" for="radio3">YES</label>').appendTo(container);  //YES
    $('<br>').appendTo(container); 
    $('<input class="k-radio" id="radio4" name="segmentActive" type="radio" value="n" >').appendTo(container);
    $('<label class="k-radio-label" for="radio4">NO</label>').appendTo(container);  //NO        
}

1 个答案:

答案 0 :(得分:2)

我不确定“已选中”是什么意思,但是可以通过处理网格的edit event来做到这一点:

editable: "inline",
edit: function(e) {
    if (e.model.isNew()) { // We are adding
        // if ($("#radio3").prop("checked")) {  // Check some field...
        $("#radio3").attr('checked', true);  // Set yes radio button
        $('input[name=segmentActive]').attr("disabled",true);  // Disable radio buttons
        // }
    }
}