Kendo网格内联编辑删除了我的下拉列表当前值

时间:2017-07-12 10:57:41

标签: jquery kendo-grid

希望有人可以帮我解决这个问题,因为过去两天我一直试图弄明白这一点。

问题:我有一个Kendo网格,它使用带有下拉列表的内联编辑。当我选择下拉菜单时,我会得到我的物品,当我更新值时,我会设置好 - 一切都好!但是,当我最初编辑项目时,网格中显示的当前值从下拉框中消失(如果我不更新该字段,则值仍然保持不变 - 编辑时不会出现。)

我的代码:

schema: {
    model: {
       id: "Id",
       fields: {
          Id: { type: "number" },
          ...
          Relationship: { type: "string" },
          ...
       }
    }
 }


columns: 
[
  { field: "Firstname", title: "Firstname" },
  ....
  { field: "RelationValue", title: "Relationship", editor: GetRelationships, 
  template: function (data) { return "<span title='" + data.Relationship + "'>" 
  + data.Relationship + "</span>" } },
  ...
  { command: ["edit"], title: "&nbsp;", width: "110px" }
],
editable: "inline"




function GetRelationships(container, options) {
        $('<input data-text-field="RelationValue" data-value-field="RelationId" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                dataTextField: "RelationValue",
                dataValueField: "RelationId",
                dataSource: {
                    transport: {
                        read: {
                            dataType: "jsonp",
                            url: "http://localhost:55719//HouseholdMembers/_GetRelationships",
                        }
                    }
                },
                change: function (e) {
                    var dataItem = e.sender.dataItem();
                    options.model.set("Relationship", dataItem.RelationValue);
                }
            });
    }

下拉列表布局

public JsonResult _GetRelationships()
{
    List<Relations> Relationships = new List<Relations>();
    Relationships.Add(new Relations() { RelationId = 1, RelationValue = "Partner" });

    return this.Jsonp(Relationships);
}

非常感谢任何帮助:)

1 个答案:

答案 0 :(得分:0)

您需要在自定义编辑器代码中自行设置下拉值。使用以下代码替换JS脚本中的代码GetRelationships

function GetRelationships(container, options) {
        $('<input data-text-field="RelationValue" data-value-field="RelationId" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                dataTextField: "RelationValue",
                dataValueField: "RelationId",
                value: options.model.RelationId, // THIS IS THE CHANGE I MADE
                dataSource: {
                    transport: {
                        read: {
                            dataType: "jsonp",
                            url: "http://localhost:55719//HouseholdMembers/_GetRelationships",
                        }
                    }
                },
                change: function (e) {
                    var dataItem = e.sender.dataItem();
                    options.model.set("Relationship", dataItem.RelationValue);
                }
            });
    }

为了您的参考,我创建了用于网格内联编辑的工作DOJO,并使用下拉列表作为编辑器。您可以在Inline Grid Editing with Dropdown As editor template访问该小提琴。

如果这不起作用,请告诉我。否则,请不要忘记将此标记为已接受的解决方案。

相关问题