在kendo可编辑网格中,下拉值在添加新记录时重置
问题描述:
我有一个可编辑的Kendo网格,其中有一个下拉列在其中一列中。将新行添加到网格后,上一个记录中的下拉值将重置,但该值将保留在模型中。在kendo可编辑网格中,下拉值在添加新记录时重置
我有created one DOJO to reproduce my issue。任何帮助将不胜感激。 Click Here!!!
答
查看此示例由Kendo Grid with Dropdown example提供。
我觉得你的代码应该是类似这种方法,
下拉列需要使用编辑器和模板,如下图所示的下拉。
columns: [{ field:"ProductName",title:"Product Name" },
{ field: "Category", title: "Category", width: "180px", editor: categoryDropDownEditor, template: "#=Category.CategoryName#" },
{ field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "130px" },
{ command: "destroy", title: " ", width: "150px" }],
下拉创建必须按照下面的方法为每个下拉菜单创建新的上下文。下面的函数将被调用如上图所示的代码
function categoryDropDownEditor(container, options) {
$('<input required name="' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataTextField: "CategoryName",
dataValueField: "CategoryID",
dataSource: {
type: "odata",
transport: {
read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
}
}
});
}
希望这有助于:)