问候大家

需要帮助,不确定哪些部分我做错了。

当单击添加新记录时,我希望segmentActive字段被禁用,默认情况下,单选按钮将被选中是。
我设法做到了。但是,当我保存记录时,它不会将值“ y”提取到数据库中。它将插入null。

$("#grid").kendoGrid({
dataSource: dataSource,
height:400,
sortable: true,
columns: [
    { field: "segmentActive", title:"STATUS", width: "120px" , editor: RadioSegmentActive,
      template: data => data.segmentActive == "y" ? "Yes" : "No" },

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

    //Button Name
    { command: [{ name: "edit", text: { edit: "Edit",
                                        update: "Submit",
                                        cancel: "Cancel"} },
                { name: "destroy", text: "De-active" }],
                  title: " ", width: "120px" },

],
editable: "inline",
edit: function(e) {
        if (e.model.isNew()) { // Went adding new record
                $('input[name=segmentActive]').attr("disabled",true);  //disable column STATUS
                radio3.checked = true; // id="radio3" checked
        }
    },
toolbar: [{ name: "create", text: "Add" }],
pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },
});  //end of kendo grid


我的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
}


先感谢您。

最佳答案

这是Kendo-您需要更新绑定到的基础模型:

edit: function(e) {
    if (e.model.isNew()) { // Went adding new record
            $('input[name=segmentActive]').attr("disabled",true);  //disable column STATUS
            radio3.checked = true; // id="radio3" checked
            // change the kendo model value
            e.model.set("segmentActive", "y");
    }
},

关于javascript - Kendo UI和Javascript-添加新记录时无法获取数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54070987/

10-11 23:27