简体   繁体   English

Kendo UI网格(内联编辑)更新和取消不起作用

[英]Kendo UI grid (inline edit) update and cancel not working

i create grid with data by javascript. 我用javascript创建数据网格。 when i click edit button at first time on any row and click update button. 当我第一次在任何行上单击编辑按钮并单击更新按钮时。 values in first row are null and then i edit other row i can't update or cancel, both button are not working. 第一行中的值为null然后我编辑其他行我无法更新或取消,两个按钮都不起作用。 when i refresh then click edit and then click cancel that row has removed i don't know why? 当我刷新然后单击编辑,然后单击取消该行已删除我不知道为什么? What's happend? 发生了什么? How to fix? 怎么修?

Data 数据

var detail = new Array();

for (var i = 1; i < 6; i++) {
     detail.push({
        Score: i,
        Condition: 0,
        ValueStart: 0,
        ValueEnd: 0,
      });
}

Grid

for (var i = 0; i < 3; i++) {
$("#GridScoreRangeContent").append("<div id='scoreRangeGrid_"+i+"'></div>");



$("#scoreRangeGrid_"+i).kendoGrid({
     dataSource: {
         data: detail,
         batch: true,
         schema: {
            model: {
              fields: {
                 Score: { editable: false },
                 Condition: { defaultValue: { Value: 1, Text: "Less than" }, validation: { required: true } },
                 ValueStart: { type: "number", validation: { required: true, min: 1 } },
                 ValueEnd: { type: "number", validation: { required: true, min: 1 } },
               }
            }
         }
      },
columns: [{ field: "Score", title: "Score" }},
         { field: "Condition", title: "Condition", editor: ScoreRangeDropDownList, template: "#=Condition#" },
         { field: "ValueStart", title: "Start" },
         { field: "ValueEnd", title: "End" },
         { command: ["edit", "destroy"], title: "&nbsp;", width: "180px" }
        ],
        editable: "inline"
 });
}

Load Dropdownlist 加载下拉列表

function ScoreRangeDropDownList(container, options) {
    $.ajax({
        url: GetUrl("Admin/Appr/LoadDropdownlist"),
        type: 'post',
        dataType: 'json',
        contentType: 'application/json',
        traditional: true,
        cache: false,
        success: function (data) {
            $('<input required data-text-field="Text" data-value-field="Value" data-bind="value:' + options.field + '"/>')
                .appendTo(container)
                .kendoDropDownList({
                    autoBind: false,
                    dataSource: data,
                    dataTextField: "Text",
                    dataValueField: "Value",
                });
        }
    });
}                                    

Kendo seems to rely on a model ID when saving/updating. 在保存/更新时,Kendo似乎依赖于模型ID。 So in your dataSource, you have to specify an id: 所以在你的dataSource中,你必须指定一个id:

model: {
    id: "Id",
    fields: {
        Id: { type: "number" },
        Score: { editable: false },
        Condition: { defaultValue: { Value: 1, Text: "Less than" }, validation: { required: true } },
        ValueStart: { type: "number", validation: { required: true, min: 1 } },
        ValueEnd: { type: "number", validation: { required: true, min: 1 } },
  }
}

What dmathisen is suggesting is definitely important but in addition it is important that the <input/> you create has a name attribute equal to the name of the column. dmathisen建议的内容绝对重要,但另外重要的是您创建的<input />的name属性等于列的名称。 You can use the value of options.field again as in the code from the Kendo Demos page example: 您可以再次使用options.field的值,如Kendo Demos页面示例中的代码所示:

// create an input element
var input = $("<input/>");
// set its 'name' to the field to which the column is bound
input.attr("name", options.field);
// append it to the container
input.appendTo(container);
// initialize a Kendo UI Widget
input.kendoDropDownList({
.
.     

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM