我正在尝试将数字微调器输入框添加到Kendo UI网格中的列中。
出于某种原因,如果我将一条记录"添加"到dataSource
并更改数值,然后"添加"另一行,则之前添加的所有行中的值都将设置为1?
$("#add-btn").click(function(){
$("#items-grid").data("kendoGrid").dataSource.add({NAME:"Apples",QTY:1})
})
$("#items-grid").kendoGrid({
height: 300,
columns : [
{
field : "NAME",
title : "Name"
},
{
field : "QTY",
title : "Qty",
width: 140 ,
template: "<input class='numeric' value='#: QTY #' style='width:100%'> </input>"
} ],
noRecords: true,
dataSource: [] ,
dataBound: function() {
this.tbody.find(".numeric").each(function(){
$(this).kendoNumericTextBox({decimals: 0});
});
}
});
http://jsfiddle.net/5ow4sj3b/
请告知
我的Kendo Grid的问题是我没有向schema
添加model
来指定QTY
列的"数字"类型。
如果没有这一点,内联numericTextBox
就不能正确地进行
dataSource : new kendo.data.DataSource({
data: [],
schema: {
model: {
fields: {
QTY: { type: "number", validation: { required: true, min: 1} }
}
}
}
}),