我正在使用带有 NumericTextBox
的 kendo ui 可编辑网格。通常在 NumericTextBox 中,小数位限制为两位,即,如果我输入 10.135,则该值将被格式化为 10.14。但我需要的是得到 10.135 本身。这里要做什么。
我的模型定义。
var GridViewModel = new kendo.data.Model.define({
fields: {
Name: { type: "string", editable: false },
Weight: { type: "number", editable: true, validation: { required: true } },
}
});
在我的 View 模型中,我已将网格设置为。
$("#DryingBinItemsAddedGrid").kendoGrid({
dataSource: {
data: DataDetails,
schema: {
model: GridViewModel
},
},
editable: true,
dataBound: function () {
},
columns: [
{
field: "Name",
title: "Name"
},
{
field: "Weight",
title: "Total Weight"
}
]
});
在这个例子中我没有提到我失败的尝试。目前我的 Weight
字段是一个带有两个字段的数字文本框。这里要做什么才能使我的 Weight
字段成为具有 3 个小数点的 NumericTextBox。
最佳答案
为了控制网格作为编辑器使用的 NumericTextBox 的配置,您需要实现一个自定义编辑器,否则,将使用 NumericTextBox 的默认配置(小数点后两位)。
尝试将“权重”列定义更改为:
{
field: "Weight",
title: "Total Weight",
editor: weightEditor
}
并添加一个实现自定义编辑器的weightEditor函数:
function weightEditor(container, options) {
$('<input name="' + options.field + '"/>')
.appendTo(container)
.kendoNumericTextBox({
decimals: 3,
})
};
关于javascript - 如何在 Kendo UI 模型定义中设置数字的小数位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40422824/