我有一个启用了内联编辑的Kendo Grid,其中有一个数字文本框来编辑数值:
$("#g_Points").kendoGrid({
dataSource: viewModel.myList,
columns: [
{ field: "Name", title: "Name", width: 250, editor: function (element, options) { element.text(options.model.Name) } },
{ field: "Available", title: "Points", width: 90, editable: true }
],
editable: true,
save: function (arg) {
arg.model.Available = arg.values.Available;
saveRow(arg.model);
this.cancelChanges();
},
scrollable: true
});
它工作正常,但我需要限制"可用"仅限正数字段。
我试过了:
...
{ field: "Available", title: "Points", width: 90, editable: true, editor: myEditorFunction }
...
function myEditorFunction (container, options) {
$('<input/>')
.appendTo(container)
.kendoNumericTextBox({
min: 0
});
}
它仅限制为正数,但保存功能不再起作用。我可以编辑值但是当我离开单元格编辑时,该值将返回默认值。
如何仅将内联数字文本框限制为正数?
答案 0 :(得分:1)
让它发挥作用,这就是我所做的:
$("#g_Points").kendoGrid({
dataSource: new kendo.data.DataSource({
data: viewModel.myList,
schema: {
model: {
fields: {
Available: { type: "number", validation: { required: true, min: 0 } }
}
}
}
}),
答案 1 :(得分:0)
看起来你必须将输入的name属性设置为字段的名称属性。
function myEditorFunction (container, options) {
$('<input name="' + options.field + '" />')
.appendTo(container)
.kendoNumericTextBox({
min: 0
});
}
有关详细信息,请参阅here。