Kendo kendo 网格编辑中的组合框不起作用
Kendo Combobox inside kendo grid edit not working
我在 kendo 网格中有一个 kendo 组合框。我使用 MVVM 绑定将组合框绑定到列表中的项目。问题是,当我 select 组合框下拉列表中的一个项目时,一切都很好,但是当我手动向组合框输入内容时,该值不会保存...这是我的网格和组合框代码:
网格:
$("#specificJoinGrid-" + this.gridID).kendoGrid({
dataSource: this.dataSource,
autoBind: true,
toolbar: ["create"],
sortable: {
mode: "multiple",
allowUnsort: true
},
columns: [
{ field: "ToField", title: OlapManagerLabels.Field, width: "20%", editor: fieldDropDownEditor.bind(this), template: "#=ToField#" },
{ field: "SpecificOperator", title: OlapManagerLabels.Operator, width: "15%", editor: operatorDropDownEditor.bind(this), template: "#=OlapManagerNamespace.getOperator(SpecificOperator)#" },
{ field: "SpecificValue", title: OlapManagerLabels.Value, width: "30%", editor: valueDropDownEditor.bind(this), template: "#=SpecificValue#" },
{ field: "SecondSpecificValue", title: OlapManagerLabels.SecondValue, width: "30%", editor: secondValDropDownEditor.bind(this), template: "#=SecondSpecificValue#" },
{ command: { name: "x", width: "5%" } }
],
editable: { createAt: "bottom" },
edit: function(e) {
var model = e.model; // access edited/newly added model
// model is observable object, use set method to trigger change event
model.ID = BINamespace.guid32();
model.set("id", model.ID);
},
selectable: true
});
数据源:
this.dataSource = new kendo.data.DataSource({
data: DataSource,
batch: true,
schema: {
model: {
id: "ID",
fields: {
ToField: { editable: true, required: true },
SpecificOperator: { editable: true, required: true, defaultValue: 6 },
SpecificValue: { editable: true },
SecondSpecificValue: { editable: true },
DataSourceID: { defaultValue: this.dataSourceID },
ID: {},
Type: { defaultValue: 1 },
ToTableID: { defaultValue: this.tableID }
}
}
}
});
组合框:
valueDropDownEditor = function (container, options) {
var grid = $("#specificJoinGrid-" + this.gridID).data("kendoGrid");
var row = grid.select();
if (options.model.SpecificOperator != 1 && options.model.SpecificOperator != 0) {
$('<input data-text-field="Key" data-value-field="Key" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoComboBox({
autoBind: false,
dataSource: this.globalsDropDownDS,
template: "#=Description# (#=Key#)",
change: value1Changed.bind(this)
});
}
else {
grid.closeCell(container);
}
}
因此,如果其他人遇到此问题,我找到了解决方案。一旦我从我的编辑器中删除了 autobind: false
属性,组合框就完全按照预期工作了。不知道为什么我花了这么长时间才弄明白这个问题,但希望它能帮助到一些人!
我在 kendo 网格中有一个 kendo 组合框。我使用 MVVM 绑定将组合框绑定到列表中的项目。问题是,当我 select 组合框下拉列表中的一个项目时,一切都很好,但是当我手动向组合框输入内容时,该值不会保存...这是我的网格和组合框代码:
网格:
$("#specificJoinGrid-" + this.gridID).kendoGrid({
dataSource: this.dataSource,
autoBind: true,
toolbar: ["create"],
sortable: {
mode: "multiple",
allowUnsort: true
},
columns: [
{ field: "ToField", title: OlapManagerLabels.Field, width: "20%", editor: fieldDropDownEditor.bind(this), template: "#=ToField#" },
{ field: "SpecificOperator", title: OlapManagerLabels.Operator, width: "15%", editor: operatorDropDownEditor.bind(this), template: "#=OlapManagerNamespace.getOperator(SpecificOperator)#" },
{ field: "SpecificValue", title: OlapManagerLabels.Value, width: "30%", editor: valueDropDownEditor.bind(this), template: "#=SpecificValue#" },
{ field: "SecondSpecificValue", title: OlapManagerLabels.SecondValue, width: "30%", editor: secondValDropDownEditor.bind(this), template: "#=SecondSpecificValue#" },
{ command: { name: "x", width: "5%" } }
],
editable: { createAt: "bottom" },
edit: function(e) {
var model = e.model; // access edited/newly added model
// model is observable object, use set method to trigger change event
model.ID = BINamespace.guid32();
model.set("id", model.ID);
},
selectable: true
});
数据源:
this.dataSource = new kendo.data.DataSource({
data: DataSource,
batch: true,
schema: {
model: {
id: "ID",
fields: {
ToField: { editable: true, required: true },
SpecificOperator: { editable: true, required: true, defaultValue: 6 },
SpecificValue: { editable: true },
SecondSpecificValue: { editable: true },
DataSourceID: { defaultValue: this.dataSourceID },
ID: {},
Type: { defaultValue: 1 },
ToTableID: { defaultValue: this.tableID }
}
}
}
});
组合框:
valueDropDownEditor = function (container, options) {
var grid = $("#specificJoinGrid-" + this.gridID).data("kendoGrid");
var row = grid.select();
if (options.model.SpecificOperator != 1 && options.model.SpecificOperator != 0) {
$('<input data-text-field="Key" data-value-field="Key" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoComboBox({
autoBind: false,
dataSource: this.globalsDropDownDS,
template: "#=Description# (#=Key#)",
change: value1Changed.bind(this)
});
}
else {
grid.closeCell(container);
}
}
因此,如果其他人遇到此问题,我找到了解决方案。一旦我从我的编辑器中删除了 autobind: false
属性,组合框就完全按照预期工作了。不知道为什么我花了这么长时间才弄明白这个问题,但希望它能帮助到一些人!